I want to start a task after my tasks have gone through five times. Is this possible in a simple way? I can't do that with a simple timer because my customers set the time in the tasks themselves. When I set a timer, the task that is supposed to start after the fifth round starts at the wrong time.
I have a program whose tasks (8 tasks) start and end one after the other. The last task then starts the first again. and I somehow need a counter that counts when the fifth round is over. So the last task must be completed for the fifth time, then this one specific task that I want to include should switch on automatically and if they is done then start the first one itself.
this is my async tasks.. it starts with button and repeats.. its only a minimized version.
async void STARTCLICK(CancellationToken token)
{
for (int i = 0; i < 2; i++)
{
try
{
token.ThrowIfCancellationRequested();
await Task.Delay(100, token);
if ()
{
}
}
catch (AggregateException)
{
MessageBox.Show("Expected");
}
catch (ObjectDisposedException)
{
MessageBox.Show("Bug");
}
catch { }
}
Thread.Sleep(2000);
var t2 = Task.Run(() => START(token));
await Task.WhenAny(new[] { t2 });
}
async void START(CancellationToken token)
{
for (int i = 0; i < 10; i++)
{
try
{
token.ThrowIfCancellationRequested();
await Task.Delay(100, token);
if ()
{
}
}
catch (AggregateException)
{
Console.WriteLine("Expected");
}
catch (ObjectDisposedException)
{
Console.WriteLine("Bug");
}
catch { }
}
Thread.Sleep(7000);
var t3 = Task.Run(() => MOVE(token));
await Task.WhenAny(new[] { t3 });
}
async void MOVE(CancellationToken token)
{
for (int i = 0; i < 4; i++)
{
try
{
token.ThrowIfCancellationRequested();
await Task.Delay(100, token);
if ()
{
}
}
catch (AggregateException)
{
Console.WriteLine("Expected");
}
catch (ObjectDisposedException)
{
Console.WriteLine("Bug");
}
catch { }
}
var t4 = Task.Run(() => RESTART(token));
await Task.WhenAny(new[] { t4 });
}
async void RESTART(CancellationToken token)
{
for (int i = 0; i < 4; i++)
{
try
{
token.ThrowIfCancellationRequested();
await Task.Delay(100, token);
if ()
{
}
}
catch (AggregateException)
{
Console.WriteLine("Expected");
}
catch (ObjectDisposedException)
{
Console.WriteLine("Bug");
}
catch { }
}
var t4 = Task.Run(() => STARTCLICK(token));
await Task.WhenAny(new[] { t4 });
is it possible to script it like this? REPAIR is the Task that i need only each 5th time... i need the token canccelation in my tasks. because the Tasks are very big and schould be stopped anytime.
Repair is a Task between EXITACCEPT and RESTART.
