Class ExecuteAsync
Executes asynchronously an Action defined on constructor method.
Inheritance
Inherited Members
Namespace: StoneCo.Framework.Background
Assembly: cs.temp.dll.dll
Syntax
public class ExecuteAsync
Constructors
ExecuteAsync(Int32, Int32, ActionDelegate)
Default constructor
Declaration
public ExecuteAsync(int repeatQuantity, int interval, ActionDelegate actionDelegate)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | repeatQuantity | Quantity of timers that action will be executed. If its defined as a number less than zero, its will execute indefinitely. |
System.Int32 | interval | Sets interval expressed in miliseconds. |
ActionDelegate | actionDelegate | Encapsulates a method kind of ActionDelegate that should receive parameters. |
Examples
Note that will be printed the second method only at interaction 3.
public class FooTest
{
public FooTest()
{
new ExecuteAsync(PrintInteracion, 3, 1000).Do();
new ExecuteAsync(PrintInteracionAndMakeStopItAfter3, 10, 1000).Do();
}
public void PrintInteracion(int currentInteractionCount, ref bool stop) => Console.WriteLine($"Current interaction: {currentInteractionCount}");
public void PrintInteracionAndMakeStopItAfter3(int currentInteractionCount, ref bool stop)
{
if (currentInteractionCount >= 3) stop = true;
Console.WriteLine($"Value of stop: {stop}\nCurrent interaction: {currentInteractionCount}");
}
}
Result:
Value of stop: False
Current interaction: 0
Current interaction: 0
Value of stop: False
Current interaction: 1
Current interaction: 1
Current interaction: 2
Value of stop: False
Current interaction: 2
Value of stop: True
Current interaction: 3
ExecuteAsync(Int32, Int32, Action)
Default constructor
Declaration
public ExecuteAsync(int repeatQuantity, int interval, Action action)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | repeatQuantity | Quantity of timers that action will be executed. If its defined as a number less than zero, its will execute indefinitely. |
System.Int32 | interval | Sets interval expressed in miliseconds. |
System.Action | action | Encapsulates a method that has no parameters and does not return a value. |
Examples
Prints 10 times, each 1 second message 'No parameters passed.'.
new FooTest();
public class FooTest
{
public FooTest() => new ExecuteAsync(PrintWithoutParameters, 10, 1000).Do();
public void PrintWithoutParameters() => Console.WriteLine("No parameters passed.");
}
ExecuteAsync(Int32, Int32, Func<Task>)
Default constructor
Declaration
public ExecuteAsync(int repeatQuantity, int interval, Func<Task> actionAsync)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | repeatQuantity | Quantity of timers that action will be executed. If its defined as a number less than zero, its will execute indefinitely. |
System.Int32 | interval | Sets interval expressed in miliseconds. |
System.Func<Task> | actionAsync | Encapsulates an Async method that has no parameters and does not return a value. |
Examples
Prints 10 times, each 1 second message 'No parameters passed.'.
new FooTest();
public class FooTest
{
public FooTest() => new ExecuteAsync(PrintWithoutParameters, 10, 1000).Do();
public Task PrintWithoutParameters() => Console.WriteLine("No parameters passed.");
}
Properties
Stop
Defines if execution must be stopped immediately.
Declaration
public bool Stop { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean | true of false |
Methods
Do(Boolean)
Starts process.
Declaration
public void Do(bool startsExecutingAction = false)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | startsExecutingAction | If true, will execute action and then at method is called. If not, only after first interval. |
Examples
View each constructor to know how to use it.