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); }
public void ConstructorWithMessageParameter() { // Act AsyncException ex = new AsyncException("the message"); // Assert Assert.AreEqual("the message", ex.Message); }
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); }
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(); }); }
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); }
public void TriggerError(AsyncException exception) { if (resultReady) { return; } this.exception = exception; lock (callbacksLock) { foreach (var cb in errorCallbacks) { cb(exception); } } tcs.TrySetException(exception); }
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(); }