Example:
I add a PostSharp attribute to a method to ensure a stopwatch is started before the method is called, and stopped just after the call returns. This method is used in a web app, so it will be called by multiple threads.
I store the result of the stopwatch timing in a static threadsafe collection, for use by all threads. This collection can then be read by another monitoring thread for the purposes of analysis.
Will this effectively force all method calls to block while they wait for the lock on the collection to be released? (so that they can complete the postsharp code block).
Would asynchronous messaging using MSMQ enable a non-blocking solution to this problem?
PostSharp Attribute code:
//...
public static ThreadSafeCollection _collection;
public override void OnInvocation(MethodInvocationEventArgs eventArgs)
{
var start = DateTime.Now;
eventArgs.Proceed();
var timeSpent = (DateTime.Now - start).TotalMilliseconds;
_collection.Add(timeSpent); //will this cause all
//method calls to methods
//decorated with this
//attribute to block on the
//_collection addition?
}
//...