C# Class Nexus.Client.ThreadedBackgroundTask

A base class for tasks that run in a background thread.
This class implements some base functionality, making writing backgounrd tasks simpler. This class handles running the task in a thread. To implement the background task, you must provide a public method that calls one of the Start or StartWait methods. If threading management is not desired, use BackgroundTask instead.
Inheritance: BackgroundTask
Show file Open project: NexusMods/NexusModManager-4.5

Public Methods

Method Description
ThreadedBackgroundTask ( ) : System

The default constructor.

Protected Methods

Method Description
DoWork ( object p_objArgs ) : object

The method that is called to start the backgound task.

DoWork ( object p_objArgs, string &p_strMessage ) : object

The method that is called to start the backgound task.

OnTaskEnded ( TaskEndedEventArgs e ) : void

Raises the IBackgroundTask.TaskEnded event.

This signals the StartWait(bool, object[]) method that the task has ended, and makes the return value accessible to said method.

Start ( ) : void

Starts the task in a foreground thread.

Start ( bool p_booRunInBackground ) : void

Starts the task, optionally in a background thread.

If the task is started in a background thread, the task will be terminated in the calling thread terminates. Otherwise, the calling thread will not terminate until the task completes.

StartWait ( ) : object

Starts the task in a foreground thread, and waits until the task completes.

StartWait ( bool p_booRunInBackground ) : object

Starts the task, optionally in a background thread, and waits until the task completes.

If the task is started in a background thread, the task will be terminated in the calling thread terminates. Otherwise, the calling thread will not terminate until the task completes.

Private Methods

Method Description
EndThreadInvokeHandler ( IAsyncResult p_asrResult ) : void

The callback use by the BeginInvoke method that runs the work in the background.

RunThread ( object p_objArgs ) : void

A wrapper to the work method called by the thread to start the work.

RunThreadedWork ( object p_objArgs ) : object

Method Details

DoWork() protected method

The method that is called to start the backgound task.
protected DoWork ( object p_objArgs ) : object
p_objArgs object Arguments to for the task execution.
return object

DoWork() protected method

The method that is called to start the backgound task.
protected DoWork ( object p_objArgs, string &p_strMessage ) : object
p_objArgs object Arguments to for the task execution.
p_strMessage string The message describing the state of the task.
return object

OnTaskEnded() protected method

Raises the IBackgroundTask.TaskEnded event.
This signals the StartWait(bool, object[]) method that the task has ended, and makes the return value accessible to said method.
protected OnTaskEnded ( TaskEndedEventArgs e ) : void
e Nexus.Client.BackgroundTasks.TaskEndedEventArgs A describing the event arguments.
return void

Start() protected method

Starts the task in a foreground thread.
protected Start ( ) : void
return void

Start() protected method

Starts the task, optionally in a background thread.
If the task is started in a background thread, the task will be terminated in the calling thread terminates. Otherwise, the calling thread will not terminate until the task completes.
protected Start ( bool p_booRunInBackground ) : void
p_booRunInBackground bool Whether the task should be run in a background thread.
return void

StartWait() protected method

Starts the task in a foreground thread, and waits until the task completes.
protected StartWait ( ) : object
return object

StartWait() protected method

Starts the task, optionally in a background thread, and waits until the task completes.
If the task is started in a background thread, the task will be terminated in the calling thread terminates. Otherwise, the calling thread will not terminate until the task completes.
protected StartWait ( bool p_booRunInBackground ) : object
p_booRunInBackground bool Whether the task should be run in a background thread.
return object

ThreadedBackgroundTask() public method

The default constructor.
public ThreadedBackgroundTask ( ) : System
return System