in PsfShimMonitor/MainWindow.xaml.cs [136:256]
private void Eventbgw_DoWork(object sender, DoWorkEventArgs e)
{
// This is the background thread
Provider etwp = e.Argument as Provider;
BackgroundWorker worker = sender as BackgroundWorker;
Thread.CurrentThread.Name = "ETWReader";
using (myTraceEventSession = new TraceEventSession(etwp.name, TraceEventSessionOptions.Create))
{
myTraceEventSession.StopOnDispose = true;
myTraceEventSession.Source.Dynamic.All += delegate (TraceEvent data) // Set Source (stream of events) from session.
{ // Get dynamic parser (knows about EventSources)
// Subscribe to all EventSource events
string operation = "";
string inputs = "";
string result = "";
string outputs = "";
string caller = "";
Int64 start = 0;
Int64 end = 0;
try
{
operation = (string)data.PayloadByName("Operation");
}
catch
{
// expected possible condition
}
try
{
inputs = (string)data.PayloadByName("Inputs");
}
catch
{
// expected possible condition
}
try
{
result = (string)data.PayloadByName("Result");
}
catch
{
// expected possible condition
}
try
{
outputs = (string)data.PayloadByName("Outputs");
}
catch
{
// expected possible condition
}
try
{
caller = (string)data.PayloadByName("Caller");
}
catch
{
// expected possible condition
}
if (inputs == null && result == null && outputs == null)
{
try
{
outputs = (string)data.PayloadByName("Message");
}
catch
{
// expected possible condition
}
}
try
{
start = (Int64)data.PayloadByName("Start");
}
catch
{
// expected possible condition
}
try
{
end = (Int64)data.PayloadByName("End");
}
catch
{
// expected possible condition
}
EventItem ei = new EventItem((int)data.EventIndex,
start,
end,
data.TimeStamp,
data.ProcessName,
data.ProcessID,
data.ThreadID,
data.ProviderName,
operation,
inputs,
result,
outputs,
caller
);
lock (_TEventListsLock)
{
_TEventListItems.Add(ei);
AddToProcIDsList(data.ProcessID);
}
worker.ReportProgress((int)data.EventIndex);
};
EventTraceProviderEnablementResultCode = myTraceEventSession.EnableProvider(etwp.guid);
if (!EventTraceProviderEnablementResultCode)
{
// Attempt resetting for second run...
myTraceEventSession.DisableProvider(etwp.guid);
EventTraceProviderEnablementResultCode = myTraceEventSession.EnableProvider(etwp.guid);
}
EventTraceProviderSourceResultCode = myTraceEventSession.Source.Process();
}
} // Eventbgw_DoWork()