Table of Contents

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

globalHookType GlobalHookType

The global hook type.

globalHookProvider IGlobalHookProvider

The underlying global hook provider, or null to use the default one.

runAsyncOnBackgroundThread bool

true 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

bool

true if the global hook has been disposed. Otherwise, false.

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

bool

true if the global hook is running. Otherwise, false.

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

disposing bool

true if the method is called from the Dispose() method. Otherwise, false.

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

e UioHookEvent

The 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

Task

A Task which finishes when the hook is stopped or disposed.

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

method string

The method which calls this method.

See Also