I need to be able to check if a specific task is running:
Task.Run(() =>
{
int counter = 720;
int sleepTime = 7000;
int operationId = 0;
Thread.CurrentThread.Name = "GetTasksStatusAsync";
......
so in my code somewhere in another class I need to check "GetTasksStatusAsync" is running. thanks
How about
Task t = Task.Run(() => ...);
if(t.Status.Equals(TaskStatus.Running))
{
//task is running
}
Basically I would store my tasks somewhere and make them accessible for other classes. Then you can check the status of the task with the code above. Refer to the TaskStatus-Documentation.
This is what worked for me.
Task t = Task.Run(() => ...);
if(t.IsCompleted.Equals(false)) // or if(t.Status.Equals(TaskStatus.WaitingForActivation)
{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With