I have the following code:
Task task = null;
var channel = System.Threading.Channels.Channel.CreateUnbounded<string>();
using (var activity = MyActivitySource.StartActivity("Parent"))
{
task = Task.Factory.StartNew(async () =>
{
//Activity.Current = null;
var item = await channel.Reader.ReadAsync();
Console.WriteLine("Task: {0}", Activity.Current?.DisplayName);
});
}
Console.WriteLine("Current end: {0}", Activity.Current?.DisplayName ?? "(null)");
await channel.Writer.WriteAsync("something");
await task;
I would like to start the task without injecting Activity. I cannot create the task outside the using(var acrivity...).
One option (I suppose) is setting Activity.Current = null at the beginning of the task. Is there an alternative option?