48 lines
1.1 KiB
C#
48 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace CommonConsole
|
|
{
|
|
class Program
|
|
{
|
|
static void Main()
|
|
{
|
|
var counter = 1;
|
|
|
|
void Executable()
|
|
{
|
|
counter = 1;
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
Console.WriteLine($"counter = {counter}");
|
|
|
|
counter++;
|
|
}
|
|
|
|
var exception = new Exception("Task end");
|
|
|
|
Console.WriteLine(exception);
|
|
Console.WriteLine();
|
|
|
|
throw exception;
|
|
}
|
|
|
|
|
|
Start(Executable).Wait();
|
|
}
|
|
|
|
static Task Start(Action action, int counter = 0)
|
|
=> Task.Factory
|
|
.StartNew(action)
|
|
.ContinueWith(_task =>
|
|
{
|
|
if (_task.Status == TaskStatus.Faulted && counter < 5)
|
|
{
|
|
Start(action, counter + 1).Wait();
|
|
}
|
|
});
|
|
}
|
|
}
|