Class BackgroundThread
Base class for easier creation and clean cancellation of a background thread.
Namespace: MarcusW.VncClient.Utils
Assembly: MarcusW.VncClient.dll
Syntax
public abstract class BackgroundThread : object, IBackgroundThread, IDisposable
Constructors
| Improve this Doc View SourceBackgroundThread(String)
Initializes a new instance of the BackgroundThread.
Declaration
protected BackgroundThread(string name)
Parameters
Type | Name | Description |
---|---|---|
System.String | name | The thread name. |
Methods
| Improve this Doc View SourceDispose()
Declaration
public void Dispose()
Dispose(Boolean)
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | disposing |
Start()
Starts the thread.
Declaration
protected void Start()
Remarks
The thread can only be started once.
StopAndWaitAsync()
Stops the thread and waits for completion.
Declaration
protected Task StopAndWaitAsync()
Returns
Type | Description |
---|---|
Task |
Remarks
It is safe to call this method multiple times.
ThreadWorker(CancellationToken)
Executes the work that should happen in the background.
Declaration
protected abstract void ThreadWorker(CancellationToken cancellationToken)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | The cancellation token that tells the method implementation when to complete. |
Events
| Improve this Doc View SourceFailed
Occurs when the background thread fails.
Declaration
public event EventHandler<BackgroundThreadFailedEventArgs>? Failed
Event Type
Type | Description |
---|---|
System.Nullable<EventHandler<BackgroundThreadFailedEventArgs>> |
Implements
IDisposable