Class BasicGlobalHookBase
- Namespace
- SharpHook
- Assembly
- SharpHook.dll
Represents an abstract implementation of IBasicGlobalHook which defines everything needed except for a strategy for handling events and uses a global hook provider (libuiohook by default).
public abstract class BasicGlobalHookBase : IBasicGlobalHook, IDisposable
- Inheritance
-
BasicGlobalHookBase
- Implements
- Derived
- Inherited Members
Constructors
BasicGlobalHookBase(GlobalHookType, IGlobalHookProvider?, bool)
Initializes a new instance of BasicGlobalHookBase.
protected BasicGlobalHookBase(GlobalHookType globalHookType = GlobalHookType.All, IGlobalHookProvider? globalHookProvider = null, bool runAsyncOnBackgroundThread = false)
Parameters
globalHookTypeGlobalHookTypeThe global hook type.
globalHookProviderIGlobalHookProviderThe underlying global hook provider, or null to use the default one.
runAsyncOnBackgroundThreadbooltrue if RunAsync() should run the hook on a background thread. Otherwise, false.
Properties
IsDisposed
Gets the value which indicates whether the global hook has been disposed.
public bool IsDisposed { get; }
Property Value
Remarks
A disposed global hook cannot be started again.
IsRunning
Gets the value which indicates whether the global hook is running.
public bool IsRunning { get; }
Property Value
Methods
AfterStop()
Defines actions to be done after the global hook is stopped. The default implementation does nothing, but it may change in a future version, so calling BeforeRun() in an overriden method is recommended.
protected virtual void AfterStop()
BeforeRun()
Defines actions to be done before the global hook is started. The default implementation does nothing, but it may change in a future version, so calling BeforeRun() in an overriden method is recommended.
protected virtual void BeforeRun()
Dispose()
Disposes of the global hook, stopping it if it is running.
public void Dispose()
Remarks
After calling this method, the hook cannot run again. If you want to stop the global hook with the ability to run it again, call the Stop() method instead.
Exceptions
- HookException
Stopping the hook has failed.
Dispose(bool)
Disposes of the global hook, stopping it if it is running. This method will not be called if the global hook is already disposed.
protected virtual void Dispose(bool disposing)
Parameters
Exceptions
- HookException
Stopping the hook has failed.
~BasicGlobalHookBase()
Stops the global hook if it's running.
[ExcludeFromCodeCoverage]
protected ~BasicGlobalHookBase()
HandleHookEvent(ref UioHookEvent)
When implemented in a derived class, represents a strategy for handling a hook event.
protected abstract void HandleHookEvent(ref UioHookEvent e)
Parameters
eUioHookEventThe event to handle.
Run()
Runs the global hook on the current thread, blocking it. The hook can be stopped temporarily by calling Stop() or stopped permanently by calling Dispose().
public void Run()
Exceptions
- HookException
Starting the global hook has failed.
- InvalidOperationException
The global hook is already running.
- ObjectDisposedException
The global hook has been disposed.
RunAsync()
Runs the global hook without blocking the current thread. The hook can be stopped temporarily by calling Stop() or stopped permanently by calling Dispose().
public Task RunAsync()
Returns
Remarks
The hook is started on a separate thread.
Exceptions
- HookException
Starting the global hook has failed.
- InvalidOperationException
The global hook is already running.
- ObjectDisposedException
The global hook has been disposed.
Stop()
Stops the global hook.
public void Stop()
Remarks
After stopping, the global hook can run again.
Exceptions
- ObjectDisposedException
The global hook has been disposed.
ThrowIfDisposed(string?)
Throws an ObjectDisposedException if this object is disposed.
protected void ThrowIfDisposed(string? method = null)
Parameters
methodstringThe method which calls this method.