-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: update the changes of Alis.Core.Aspect.Thread module
- Loading branch information
Showing
5 changed files
with
48 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,29 @@ | ||
# ThreadTask Class | ||
|
||
The `ThreadTask` class is part of the `Alis.Core.Aspect.Thread` namespace. It is used to encapsulate an action that can be executed in a separate thread. | ||
The `ThreadTask` class is part of the `Alis.Core.Aspect.Thread` namespace. It is used to encapsulate a task that will be executed in a separate thread. | ||
|
||
## Properties | ||
|
||
- `Action Action { get; set; }`: This property holds the action that will be executed when the `Execute` method is called. | ||
- `Action<CancellationToken> Action`: This private property holds the action that will be executed when the task is started. | ||
- `CancellationToken Token`: This private property holds the cancellation token that can be used to request the cancellation of the task. | ||
|
||
## Constructor | ||
|
||
- `ThreadTask(Action action)`: This constructor initializes a new instance of the `ThreadTask` class. It takes an `Action` as a parameter, which is the action that will be executed when the `Execute` method is called. | ||
- `ThreadTask(Action<CancellationToken> action, CancellationToken token)`: This constructor creates a new instance of the `ThreadTask` class with the given action and cancellation token. | ||
|
||
## Methods | ||
|
||
- `void Execute()`: This method invokes the action that was passed to the constructor. It does not return a value. | ||
- `void Execute(CancellationToken token)`: This method executes the action of the task, passing the cancellation token to it. | ||
|
||
## Usage | ||
|
||
Here is an example of how to use the `ThreadTask` class: | ||
|
||
```csharp | ||
ThreadTask task = new ThreadTask(() => | ||
CancellationTokenSource cts = new CancellationTokenSource(); | ||
ThreadTask task = new ThreadTask(token => | ||
{ | ||
// Your code here | ||
}); | ||
}, cts.Token); | ||
|
||
task.Execute(); | ||
``` | ||
|
||
In this example, a new `ThreadTask` is created with an action. The action is then executed by calling the `Execute` method. | ||
task.Execute(cts.Token); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters