private void CallCallbackPossiblyUnderLock(SendOrPostCallback callback, Object state) { ThreadContext threadContext = null; try { threadContext = _application.OnThreadEnter(); try { callback(state); } catch (Exception e) { _error = ExceptionDispatchInfo.Capture(e); } } finally { if (threadContext != null) { threadContext.DisassociateFromCurrentThread(); } } }