When using async Task method it is required to place await before method. I need code to be executed in non UI blocking manner and don't want to await. My only idea is to use:
private void TaskFactory()
{
CancellationTokenSource token_TaskFactory = new CancellationTokenSource();
ParallelOptions parOpts = new ParallelOptions();
parOpts.CancellationToken = token_TaskFactory.Token;
parOpts.MaxDegreeOfParallelism = Environment.ProcessorCount;
TaskCreationOptions atp = new TaskCreationOptions();
atp = TaskCreationOptions.PreferFairness;
Task TaskFactory = Task.Factory.StartNew(() =>
{
if (!token_TaskFactory.IsCancellationRequested)
{
Thread.Sleep(5000);
}
else
{
}
}, token_TaskFactory.Token, atp, TaskScheduler.Default);
}