private void ProcessAsyncRequest(AsyncRequest request)
{
request.Error = null;
try
{
request.Result = request.Method();
}
catch (Exception ex)
{
_log.Error("Call to requested method failed with exception.", ex);
request.Result = null;
request.Error = ex;
// do nothing here we will send error info when invoking callback
}
try
{
if (_synchronizationContext == SynchronizationContext.Current)
{
// Execute callback on the current thread
request.Callback(request.Result, request.Error);
}
else
{
// Post the callback on the creator thread
_synchronizationContext.Post(new SendOrPostCallback(delegate(object state)
{
var r = state as AsyncRequest;
r.Callback(r.Result, r.Error);
}), request);
}
}
catch (Exception ex)
{
_log.Error("Unable to invoke callback method.", ex);
}
}