当前位置: 首页>>代码示例>>C#>>正文


C# AsyncResult.Complete方法代码示例

本文整理汇总了C#中AsyncResult.Complete方法的典型用法代码示例。如果您正苦于以下问题:C# AsyncResult.Complete方法的具体用法?C# AsyncResult.Complete怎么用?C# AsyncResult.Complete使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AsyncResult的用法示例。


在下文中一共展示了AsyncResult.Complete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: when_asyncressult_completes_on_different_thread

 public when_asyncressult_completes_on_different_thread()
 {
     asyncResult = new AsyncResult<int>(ar => Thread.VolatileWrite(ref callbackWasInvoked, 1), null);
     ThreadPool.QueueUserWorkItem(_ => asyncResult.Complete(true, ExpectedResult));
     // give the thread-pool thread time to invoke the callback
     Thread.Sleep(100);
 }
开发者ID:peteraritchie,项目名称:EffectiveAsyncResult,代码行数:7,代码来源:when_asyncressult_completes_on_different_thread.cs

示例2: TestCallback

 public void TestCallback()
 {
     AsyncResult result;
      Boolean called;
      // callback with null state
      called = false;
      result = new AsyncResult(
     ar =>
     {
        Assert.IsNull(ar.AsyncState);
        Assert.IsFalse(ar.CompletedSynchronously);
        Assert.IsTrue(ar.IsCompleted);
        Assert.IsTrue(ar.AsyncWaitHandle.WaitOne(0));
        called = true;
     },
     null
      );
      Assert.IsNull(result.AsyncState);
      Assert.IsFalse(result.IsCompleted);
      Assert.IsFalse(called);
      result.Complete(null);
      Assert.IsTrue(called);
      // callback with valid state
      called = false;
      result = new AsyncResult(
     ar =>
     {
        Assert.AreEqual(ar.AsyncState, 1);
        Assert.IsFalse(ar.CompletedSynchronously);
        Assert.IsTrue(ar.IsCompleted);
        Assert.IsTrue(ar.AsyncWaitHandle.WaitOne(0));
        called = true;
     },
     1
      );
      Assert.AreEqual(result.AsyncState, 1);
      Assert.IsFalse(result.IsCompleted);
      Assert.IsFalse(called);
      result.Complete(null);
      Assert.IsTrue(called);
 }
开发者ID:modulexcite,项目名称:WcfEx,代码行数:41,代码来源:TestAsyncResult.cs

示例3: when_asyncresult_is_used_with_operation_throwing_exception

 public when_asyncresult_is_used_with_operation_throwing_exception()
 {
     asyncResult =
         new AsyncResult<string>(ar => { }, null);
     Task.Factory.StartNew(() => asyncResult.Complete(true, new InvalidOperationException()));
 }
开发者ID:peteraritchie,项目名称:EffectiveAsyncResult,代码行数:6,代码来源:when_asyncresult_is_used_with_operation_throwing_exception.cs

示例4: JobFinished

 private void JobFinished(AsyncResult<IOutput> jar, IOutput outp)
 {
     try
     {
         FreeStreamId(jar.StreamId);
     }
     finally
     {
         jar.SetResult(outp);
         jar.Complete();
         (outp as IWaitableForDispose).WaitForDispose();
     }
 }
开发者ID:randacc,项目名称:csharp-driver,代码行数:13,代码来源:CassandraConnection.cs

示例5: BeginConnect

 public IAsyncResult BeginConnect(AsyncCallback callback, object state)
 {
     var result = new AsyncResult(callback, state);
     result.Complete();
     return result;
 }
开发者ID:haroldma,项目名称:Universal.Torrent,代码行数:6,代码来源:HTTPConnection.cs

示例6: ExecuteAsync

 private void ExecuteAsync(GpgCommand command, Stream input, Stream output, AsyncResult result)
 {
     try
     {
         Execute(command, input, output);
         result.Complete();
     }
     catch(Exception ex)
     {
         result.Throw(ex);
     }
 }
开发者ID:awhatley,项目名称:cryptophage,代码行数:12,代码来源:GpgCommandExecutor.cs

示例7: BeginHandshake

        /// <summary>
        ///     Begins the message stream encryption handshaking process
        /// </summary>
        /// <param name="socket">The socket to perform handshaking with</param>
        /// <param name="callback">The callback.</param>
        /// <param name="state">The state.</param>
        /// <returns></returns>
        public virtual IAsyncResult BeginHandshake(IConnection socket, AsyncCallback callback, object state)
        {
            if (socket == null)
                throw new ArgumentNullException(nameof(socket));

            if (AsyncResult != null)
                throw new ArgumentException("BeginHandshake has already been called");

            AsyncResult = new AsyncResult(callback, state);

            try
            {
                _socket = socket;

                // Either "1 A->B: Diffie Hellman Ya, PadA" or "2 B->A: Diffie Hellman Yb, PadB"
                // These two steps will be done simultaneously to save time due to latency
                SendY();
                ReceiveY();
            }
            catch (Exception ex)
            {
                AsyncResult.Complete(ex);
            }
            return AsyncResult;
        }
开发者ID:haroldma,项目名称:Universal.Torrent,代码行数:32,代码来源:EncryptedSocket.cs

示例8: BeginSendMessage

        void BeginSendMessage(string msg, int i, AsyncResult rar)
        {
            try
            {
                _jc.BeginSendMessage(_to[i], msg, ar =>
                {
                    try
                    {
                        _jc.EndSendMessage(ar);
                    }
                    catch (Exception ex)
                    {
                        rar.Complete(i == 0, ex);
                        return;
                    }

                    if (++i >= _to.Length)
                    {
                        rar.Complete(false);
                    }
                    else
                    {
                        BeginSendMessage(msg, i, rar);
                    }
                },
                null);
            }
            catch (Exception ex)
            {
                rar.Complete(i == 0, ex);
            }
        }
开发者ID:bbyk,项目名称:xmppasync,代码行数:32,代码来源:JabberAppender.cs

示例9: BeginExecuteReader

			public IAsyncResult BeginExecuteReader(AsyncCallback callback)
			{
				AsyncResult<IDataReader> asyncResult = new AsyncResult<IDataReader>(callback, this);

				Task.Factory.StartNew(() =>
				{
					try
					{
						IDataReader dataReader = ExecureEventLogReader();
						asyncResult.Complete(dataReader, false);
					}
					catch (Exception exc)
					{
						asyncResult.HandleException(exc, false);
					}
				});

				return asyncResult;
			}
开发者ID:saycale,项目名称:MSSQLServerAuditor,代码行数:19,代码来源:EventLogQueryConnection.cs

示例10: BeginReadMessage

		public static IAsyncResult BeginReadMessage(object guidOrServer, Connection connection, AsyncCallback callback, object asyncState)
		{
			lock (_listenersLockObject)
			{
				Debug.Assert(!_listeners.Contains(guidOrServer), "Handler for this guid already registered.");

				AsyncResult ar = new AsyncResult(connection, callback, asyncState);
				if (outstandingMessages.Contains(guidOrServer))
				{
					Stack outstanding = (Stack)outstandingMessages[guidOrServer];
					if (outstanding.Count > 0)
					{
						object[] result = (object[])outstanding.Pop();
						ar.Complete((Connection)result[0], (Message)result[1]);
						return ar;
					}
				}
				_listeners.Add(guidOrServer, ar);
				return ar;
			}
		}
开发者ID:yallie,项目名称:zyan,代码行数:21,代码来源:Manager.cs

示例11: BeginReadMessage

		public static IAsyncResult BeginReadMessage(object guidOrServer, Connection connection, AsyncCallback callback, object asyncState)
		{
			lock (_listenersLockObject)
			{
				Debug.Assert(!_listeners.ContainsKey(guidOrServer), "Handler for this guid already registered.");

				var ar = new AsyncResult(connection, callback, asyncState);

				// process pending message
				Queue<ConnectionAndMessage> queue;
				if (pendingMessages.TryGetValue(guidOrServer, out queue))
				{
					if (queue.Count > 0)
					{
						var result = queue.Dequeue();
						ar.Complete(result.Connection, result.Message);
						return ar;
					}
				}

				// or start listening for incoming messages
				_listeners.Add(guidOrServer, ar);
				return ar;
			}
		}
开发者ID:yallie,项目名称:zyan,代码行数:25,代码来源:Manager.cs

示例12: TestCompletion

 public void TestCompletion()
 {
     AsyncResult result;
      // default completion
      result = new AsyncResult(null, null);
      Assert.IsFalse(result.CompletedSynchronously);
      Assert.IsFalse(result.IsCompleted);
      Assert.IsFalse(result.AsyncWaitHandle.WaitOne(0));
      Assert.IsFalse(result.AsyncWaitHandle.WaitOne(1));
      result.Complete(null);
      Assert.IsFalse(result.CompletedSynchronously);
      Assert.IsTrue(result.IsCompleted);
      Assert.IsTrue(result.AsyncWaitHandle.WaitOne(0));
      Assert.IsTrue(result.AsyncWaitHandle.WaitOne(1));
      // completion with callback
      result = new AsyncResult(o => { }, null);
      Assert.IsFalse(result.CompletedSynchronously);
      Assert.IsFalse(result.IsCompleted);
      Assert.IsFalse(result.AsyncWaitHandle.WaitOne(0));
      Assert.IsFalse(result.AsyncWaitHandle.WaitOne(1));
      result.Complete(null);
      Assert.IsFalse(result.CompletedSynchronously);
      Assert.IsTrue(result.IsCompleted);
      Assert.IsTrue(result.AsyncWaitHandle.WaitOne(0));
      Assert.IsTrue(result.AsyncWaitHandle.WaitOne(1));
      // completion with callback/state
      result = new AsyncResult(o => { }, 1);
      Assert.IsFalse(result.CompletedSynchronously);
      Assert.IsFalse(result.IsCompleted);
      Assert.IsFalse(result.AsyncWaitHandle.WaitOne(0));
      Assert.IsFalse(result.AsyncWaitHandle.WaitOne(1));
      result.Complete(null);
      Assert.IsFalse(result.CompletedSynchronously);
      Assert.IsTrue(result.IsCompleted);
      Assert.IsTrue(result.AsyncWaitHandle.WaitOne(0));
      Assert.IsTrue(result.AsyncWaitHandle.WaitOne(1));
      // completion with exception
      result = new AsyncResult(o => { }, 1);
      Assert.IsFalse(result.CompletedSynchronously);
      Assert.IsFalse(result.IsCompleted);
      Assert.IsFalse(result.AsyncWaitHandle.WaitOne(0));
      Assert.IsFalse(result.AsyncWaitHandle.WaitOne(1));
      result.Complete(null, new Exception("exception"));
      Assert.IsFalse(result.CompletedSynchronously);
      Assert.IsTrue(result.IsCompleted);
      Assert.IsTrue(result.AsyncWaitHandle.WaitOne(0));
      Assert.IsTrue(result.AsyncWaitHandle.WaitOne(1));
      // multiple completion
      result = new AsyncResult(o => { }, 1);
      result.Complete(null, new Exception("exception"));
      Assert.IsFalse(result.CompletedSynchronously);
      Assert.IsTrue(result.IsCompleted);
      Assert.IsTrue(result.AsyncWaitHandle.WaitOne(0));
      Assert.IsTrue(result.AsyncWaitHandle.WaitOne(1));
      try
      {
     result.Complete(null);
     Assert.Fail("Exception expected");
      }
      catch (AssertFailedException) { throw; }
      catch { }
 }
开发者ID:modulexcite,项目名称:WcfEx,代码行数:62,代码来源:TestAsyncResult.cs

示例13: TestWait

 public void TestWait()
 {
     AsyncResult result;
      // default timeout
      result = new AsyncResult(null, null);
      Assert.AreEqual(result.Timeout, TimeSpan.MaxValue);
      Assert.IsFalse(result.TryWaitFor(TimeSpan.Zero));
      Assert.IsFalse(result.TryWaitFor(TimeSpan.FromMilliseconds(1)));
      try
      {
     result.WaitFor(TimeSpan.Zero);
     Assert.Fail("TimeoutException expected");
      }
      catch (TimeoutException) { }
      try
      {
     result.WaitFor(TimeSpan.FromMilliseconds(1));
     Assert.Fail("TimeoutException expected");
      }
      catch (TimeoutException) { }
      result.Complete("complete", new Exception("exception"));
      Assert.IsTrue(result.TryWaitFor(TimeSpan.Zero));
      Assert.IsTrue(result.TryWaitFor(TimeSpan.MaxValue));
      result.WaitFor();
      result.WaitFor(TimeSpan.Zero);
      result.WaitFor(TimeSpan.MaxValue);
      // valid timeout
      result = new AsyncResult(null, null, TimeSpan.FromMilliseconds(10));
      Assert.AreEqual(result.Timeout, TimeSpan.FromMilliseconds(10));
      Assert.IsFalse(result.TryWaitFor(TimeSpan.Zero));
      Assert.IsFalse(result.TryWaitFor(TimeSpan.FromMilliseconds(1)));
      try
      {
     result.WaitFor(TimeSpan.Zero);
     Assert.Fail("TimeoutException expected");
      }
      catch (TimeoutException) { }
      try
      {
     result.WaitFor(TimeSpan.FromMilliseconds(1));
     Assert.Fail("TimeoutException expected");
      }
      catch (TimeoutException) { }
      try
      {
     result.WaitFor();
     Assert.Fail("TimeoutException expected");
      }
      catch (TimeoutException) { }
      result.Complete("complete", new Exception("exception"));
      Assert.IsTrue(result.TryWaitFor(TimeSpan.Zero));
      Assert.IsTrue(result.TryWaitFor(TimeSpan.MaxValue));
      result.WaitFor();
      result.WaitFor(TimeSpan.Zero);
      result.WaitFor(TimeSpan.MaxValue);
 }
开发者ID:modulexcite,项目名称:WcfEx,代码行数:56,代码来源:TestAsyncResult.cs

示例14: TestState

 public void TestState()
 {
     AsyncResult result;
      // null state
      result = new AsyncResult(null, null);
      Assert.IsNull(result.AsyncState);
      Assert.IsFalse(result.IsCompleted);
      result.Complete(null);
      Assert.IsNull(result.AsyncState);
      Assert.IsTrue(result.IsCompleted);
      // valid state
      result = new AsyncResult(null, 1);
      Assert.AreEqual(result.AsyncState, 1);
      Assert.IsFalse(result.IsCompleted);
      result.Complete(null);
      Assert.AreEqual(result.AsyncState, 1);
      Assert.IsTrue(result.IsCompleted);
      // callback + state
      result = new AsyncResult(o => { }, 2);
      Assert.AreEqual(result.AsyncState, 2);
      Assert.IsFalse(result.IsCompleted);
      result.Complete(null);
      Assert.AreEqual(result.AsyncState, 2);
      Assert.IsTrue(result.IsCompleted);
 }
开发者ID:modulexcite,项目名称:WcfEx,代码行数:25,代码来源:TestAsyncResult.cs

示例15: TestResult

 public void TestResult()
 {
     AsyncResult result;
      // null result
      result = new AsyncResult(null, null);
      Assert.IsFalse(result.IsFaulted);
      result.Complete(null);
      Assert.AreEqual(result.GetResult(), null);
      Assert.AreEqual(result.GetResult<String>(), null);
      Assert.IsTrue(result.IsCompleted);
      Assert.IsFalse(result.IsFaulted);
      // non-null result
      result = new AsyncResult(null, null);
      Assert.IsFalse(result.IsFaulted);
      result.Complete("complete");
      Assert.AreEqual(result.GetResult(), "complete");
      Assert.AreEqual(result.GetResult<String>(), "complete");
      try
      {
     result.GetResult<Int32>();
     Assert.Fail("InvalidCastException expected");
      }
      catch (InvalidCastException) { }
      Assert.IsTrue(result.IsCompleted);
      Assert.IsFalse(result.IsFaulted);
      // exception result
      result = new AsyncResult(null, null);
      Assert.IsFalse(result.IsFaulted);
      result.Complete(null, new Exception("exception"));
      try
      {
     result.GetResult();
     Assert.Fail("Exception expected");
      }
      catch (Exception e)
      {
     Assert.AreEqual(e.Message, "exception");
      }
      Assert.IsTrue(result.IsCompleted);
      Assert.IsTrue(result.IsFaulted);
      // exception with typed result
      result = new AsyncResult(null, null);
      Assert.IsFalse(result.IsFaulted);
      result.Complete("complete", new Exception("exception"));
      try
      {
     result.GetResult<String>();
     Assert.Fail("Exception expected");
      }
      catch (Exception e)
      {
     Assert.AreEqual(e.Message, "exception");
      }
      Assert.IsTrue(result.IsCompleted);
      Assert.IsTrue(result.IsFaulted);
      // exception with invalid typed result
      result = new AsyncResult(null, null);
      Assert.IsFalse(result.IsFaulted);
      result.Complete("complete", new Exception("exception"));
      try
      {
     result.GetResult<Int32>();
     Assert.Fail("Exception expected");
      }
      catch (Exception e)
      {
     Assert.AreEqual(e.Message, "exception");
      }
      Assert.IsTrue(result.IsCompleted);
      Assert.IsTrue(result.IsFaulted);
 }
开发者ID:modulexcite,项目名称:WcfEx,代码行数:71,代码来源:TestAsyncResult.cs


注:本文中的AsyncResult.Complete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。