1

I am intercepting wcf calls of services I host in my application in order to display data about the service (how many calls each method handled, log the methods parameters etc`). In addition to that, I want to measure the execution time of each method.

I am already wrapping the instance with Castle interceptor, and I use StopWatch to measure the sync methods.

However, I can not use stopwatch on async method because I have 2 different methods (for beginInvoke and EndInvoke, I intercept the WCF invoker).

How can I measure the execution time, or at least relate the invocations of Begin and End?

Thanks

Tomer K
  • 11
  • 2

2 Answers2

0

It's sounds like this question was already answered here Using the Stopwatch with Async methods

Cheers

Community
  • 1
  • 1
zcharles
  • 190
  • 6
0

Got it,

I realized that the invocation.ReturnValue holds the task so all I had to do is Implementing a TaskInterceptor :

public class TaskInterceptor : IInterceptor
{
    public void Intercept(IInvocation invocation)
    {
        var task = invocation.ReturnValue as Task;

        InterceptBeforeInvoking();

        invocation.Proceed();

        task.ContinueWith(InterceptAfterInvocation);


    }

    private void InterceptAfterInvocation(Task obj)
    {


    }

    private void InterceptBeforeInvoking()
    {


    }
}
Tomer K
  • 11
  • 2