Need your help to understand how can we log ETW events to track Task started & Task completed inside parallel.foreach. I basically need to see when event got fired.
I have gone through few examples which are available in web but not able to use it inside parallel.foreach.
Below is code snippet where I want to trace the ETW events. Thanks for your help & suggestion.
List<int> integerList = Enumerable.Range(0, 2).ToList();
Parallel.ForEach(integerList, i =>
{
try
{
Console.WriteLine(@"Print of i = {0}, thread = {1},thread status = {2}", i, Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.ThreadState);
}
catch (Exception ex)
{
Console.WriteLine(@" Catch value of Exception = {0},Thread Id {1},Thread State {2}", ex.ToString(), Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.ThreadState);
}
finally {
Console.WriteLine(@" Finally block value of i = {0}, thread = {1},thread status = {2}", i, Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.ThreadState);
}
});
Console.ReadLine();