示例#1
0
    public void Replace()
    {
      var syncContext = Current;

      if (syncContext == null)
        throw new InvalidOperationException(
          "Ensure a synchronization context exists before calling this method.");

      var customSynchronizationContext = syncContext as AsyncExceptionSwallowingContext;

      if (customSynchronizationContext == null)
      {
        customSynchronizationContext = new AsyncExceptionSwallowingContext(syncContext);
        SetSynchronizationContext(customSynchronizationContext);
      }
      else
      {
        SetSynchronizationContext(_syncContext);
      }
    }
示例#2
0
        public void Replace()
        {
            var syncContext = Current;

            if (syncContext == null)
            {
                throw new InvalidOperationException(
                          "Ensure a synchronization context exists before calling this method.");
            }

            var customSynchronizationContext = syncContext as AsyncExceptionSwallowingContext;

            if (customSynchronizationContext == null)
            {
                customSynchronizationContext = new AsyncExceptionSwallowingContext(syncContext);
                SetSynchronizationContext(customSynchronizationContext);
            }
            else
            {
                SetSynchronizationContext(_syncContext);
            }
        }