In my console app I start a new background thread to process some long running operation. I have the following code
Task.Factory.StartNew(
() =>
{
try
{
// do some work
}
catch (MyException e)
{
logger.LogError(e);
throw;
}
},
cancellationToken,
TaskCreationOptions.LongRunning,
TaskScheduler.Default)
.ConfigureAwait(false);
I need to catch any exception, log it and re-throw to the main thread. I run it in docker container, and after exception it should restart. In this case, an exception logged, but application still working. How to throw it up to main thread to stop application?
It is not duplicate, because I use TaskCreationOptions.LongRunning
. It not work for TaskCreationOptions.LongRunning
!!!