Hi,
Due to modern application design it is important to work as parallel as you cankinda divide and conquer (and merge). In order to followthe paradigma of parallel programming, many callsare executed asynchronous -but then later reading the application trace will be muchharder.
So my question: Is there a simple way toinformation from the .Net Frameworkfor the questionwho is thecallerofthe currently executed asynchronous call.What wouldbe the bestapproach to get this information (IL rewriting ? ), any ideas ?
Thank you, Holger
- Edited byholger heinrich Tuesday, May 26, 2009 6:57 PMTypo
-
AnswersWednesday, May 27, 2009 12:00 AM p.b.a      There are a variety of ways to start asynchronous jobs - calling a delegate's BeginInvoke, using ThreadPool.QueueUserWorkItem or using System.Threading.Tasks - but they all (AFAIK) take a delegate callback as a parameter. Using IL rewriting you could add a new field to the delegate which will store the async operation initiation stack trace so all you need to do next is automatically populate that field at runtime. Ideally you would rewrite the methods that schedule async operations (QueueUserWorkItem, task factory's StartNew) but that is not always possible because some of them are generated at runtime - like BeginInvoke methods - and cannot be rewritten. What I would do is rewrite MulticastDelegate's (or Delegate's) constructors to automatically register the call stack, this will at least tell you when the callback delegate was created. Another solution would be to register for function enter, monitor for the required methods (QueueUserWorkItem, etc), get the stack right there then expose a service to the managed code to get the stack back. The problem with this approach is resource management, you need to clean up the data for the delegates that are gone - have been garbage collected. HTH Paul
- Edited byp.b.a Wednesday, May 27, 2009 12:01 AMtypo
- Marked As Answer byDavid BromanMSFT, OwnerFriday, May 29, 2009 4:19 PM
- Edited byp.b.a Wednesday, May 27, 2009 1:44 AM
-
All RepliesWednesday, May 27, 2009 12:00 AM p.b.a      There are a variety of ways to start asynchronous jobs - calling a delegate's BeginInvoke, using ThreadPool.QueueUserWorkItem or using System.Threading.Tasks - but they all (AFAIK) take a delegate callback as a parameter. Using IL rewriting you could add a new field to the delegate which will store the async operation initiation stack trace so all you need to do next is automatically populate that field at runtime. Ideally you would rewrite the methods that schedule async operations (QueueUserWorkItem, task factory's StartNew) but that is not always possible because some of them are generated at runtime - like BeginInvoke methods - and cannot be rewritten. What I would do is rewrite MulticastDelegate's (or Delegate's) constructors to automatically register the call stack, this will at least tell you when the callback delegate was created. Another solution would be to register for function enter, monitor for the required methods (QueueUserWorkItem, etc), get the stack right there then expose a service to the managed code to get the stack back. The problem with this approach is resource management, you need to clean up the data for the delegates that are gone - have been garbage collected. HTH Paul
- Edited byp.b.a Wednesday, May 27, 2009 12:01 AMtypo
- Marked As Answer byDavid BromanMSFT, OwnerFriday, May 29, 2009 4:19 PM
- Edited byp.b.a Wednesday, May 27, 2009 1:44 AM
-
Thank you Paul for your detailed, helpfulideas.
| | holger heinrich |
|