コード例 #1
0
ファイル: AsyncReply.cs プロジェクト: esiur/esiur-dotnet
    public AsyncReply TriggerError(Exception exception)
    {
        //timeout?.Dispose();

        if (resultReady)
        {
            return(this);
        }

        if (exception is AsyncException)
        {
            this.exception = exception as AsyncException;
        }
        else
        {
            this.exception = new AsyncException(exception);
        }


        // lock (callbacksLock)
        // {
        foreach (var cb in errorCallbacks)
        {
            cb(this.exception);
        }
        //  }

        mutex?.Set();

        return(this);
    }
コード例 #2
0
        public void ConstructorWithMessageParameter() {
            // Act
            AsyncException ex = new AsyncException("the message");

            // Assert
            Assert.AreEqual("the message", ex.Message);
        }
コード例 #3
0
        public void ConstructorWithMessageAndInnerExceptionParameter() {
            // Arrange
            Exception innerException = new Exception();

            // Act
            AsyncException ex = new AsyncException("the message", innerException);

            // Assert
            Assert.AreEqual("the message", ex.Message);
            Assert.AreEqual(innerException, ex.InnerException);
        }
コード例 #4
0
 public AsyncAwaiter(AsyncReply <T> reply)
 {
     reply.Then(x =>
     {
         this.IsCompleted = true;
         this.result      = (T)x;
         this.callback?.Invoke();
     }).Error(x =>
     {
         exception        = x;
         this.IsCompleted = true;
         this.callback?.Invoke();
     });
 }
コード例 #5
0
        public void TypeIsSerializable() {
            // Arrange
            MemoryStream ms = new MemoryStream();
            BinaryFormatter formatter = new BinaryFormatter();
            AsyncException ex = new AsyncException("the message", new Exception("inner exception"));

            // Act
            formatter.Serialize(ms, ex);
            ms.Position = 0;
            AsyncException deserialized = formatter.Deserialize(ms) as AsyncException;

            // Assert
            Assert.IsNotNull(deserialized, "Deserialization process did not return the exception.");
            Assert.AreEqual("the message", deserialized.Message);
            Assert.IsNotNull(deserialized.InnerException);
            Assert.AreEqual("inner exception", deserialized.InnerException.Message);
        }
コード例 #6
0
    public void TriggerError(AsyncException exception)
    {
        if (resultReady)
        {
            return;
        }

        this.exception = exception;


        lock (callbacksLock)
        {
            foreach (var cb in errorCallbacks)
            {
                cb(exception);
            }
        }

        tcs.TrySetException(exception);
    }
コード例 #7
0
        static void Main(string[] args)
        {
            // 测试异步异常
            //ShowThreadId();
            //AsyncException.TryTestExceptionAsync().Wait();
            //ShowThreadId();

            // 测试Async上下文捕获机制
            //Console.WriteLine("---------测试Async捕获上下文机制-----------");
            //ConfigureAwaitTestAsync().Wait();

            // 测试进度报告
            //AsyncIProgress.CallMyProgessAsync().Wait();

            // 测试WhenAll
            //System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            //sw.Start();
            //AsyncWhenAll.TestWhenAllAsync().Wait();
            //sw.Stop();
            //Console.WriteLine(sw.Elapsed.TotalSeconds + " s");

            //AsyncWhenAll.TestWhenAllResultIntArrayAsync().Result.ToList().ForEach(x => Console.WriteLine(x));
            //AsyncWhenAll.DownloadAllUrlsHtmlAsync(new List<string>()
            //{
            //    "http://www.baidu.com",
            //    "http://www.google.com"
            //}).Result.ToList().ForEach(x => Console.WriteLine(x));

            AsyncException.TestThrowExceptionAsync().Wait();

            //AsyncCancellationToken.IssueCancellRequest().Wait();

            Console.WriteLine("ok");

            Console.ReadKey();
        }