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


C# AsyncResult类代码示例

本文整理汇总了C#中AsyncResult的典型用法代码示例。如果您正苦于以下问题:C# AsyncResult类的具体用法?C# AsyncResult怎么用?C# AsyncResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: BeginRead

 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
 {
     read = new AsyncResult() { AsyncState = state };
     read.bytesRead = Read(buffer, offset, count);
     callback(read);
     return read;
 }
开发者ID:nithinphilips,项目名称:bbwifimusicsync,代码行数:7,代码来源:SynchronousMemoryStream.cs

示例2: BeginGetQuestionnaireTemplateSummary

        public IAsyncResult BeginGetQuestionnaireTemplateSummary(QuestionnaireTemplate questionnaireTemplate, AsyncCallback callback, object asyncState)
        {
            var result = new AsyncResult<QuestionnaireTemplateSummary>(callback, asyncState);
            HandleBeginGetQuestionnaireTemplateSummary(result);

            return result;
        }
开发者ID:CarlosVV,项目名称:mediavf,代码行数:7,代码来源:MockQuestionnaireService.cs

示例3: BeginWrite

      public IAsyncResult BeginWrite(ReaderWriterGateCallback callback, Object state,
        AsyncCallback asyncCallback, Object asyncState) {
         AsyncResult<Object> ar = new AsyncResult<Object>(asyncCallback, asyncState);
         ReaderWriterGateReleaser releaser = new ReaderWriterGateReleaser(callback, this, false, state, ar);
         m_syncLock.Enter(true);
         switch (m_state) {
            case ReaderWriterGateStates.Free:             // If Free "RFW -> OBW, invoke, return
            case ReaderWriterGateStates.ReservedForWriter:
               m_state = ReaderWriterGateStates.OwnedByWriter;
               ThreadPool.QueueUserWorkItem(releaser.Invoke);
               break;

            case ReaderWriterGateStates.OwnedByReaders:   // If OBR | OBRAWP -> OBRAWP, queue, return
            case ReaderWriterGateStates.OwnedByReadersAndWriterPending:
               m_state = ReaderWriterGateStates.OwnedByReadersAndWriterPending;
               m_qWriteRequests.Enqueue(releaser);
               break;

            case ReaderWriterGateStates.OwnedByWriter:   // If OBW, queue, return
               m_qWriteRequests.Enqueue(releaser);
               break;
         }
         m_syncLock.Leave();
         return ar;
      }
开发者ID:blinds52,项目名称:PowerThreading,代码行数:25,代码来源:ReaderWriterGate.cs

示例4: BeginGetQuestionnaire

        public IAsyncResult BeginGetQuestionnaire(AsyncCallback callback, object asyncState)
        {
            var result = new AsyncResult<Questionnaire>(callback, asyncState);
            HandleBeginGetQuestionnaire(result);

            return result;
        }
开发者ID:tian1ll1,项目名称:WPF_Examples,代码行数:7,代码来源:MockQuestionnaireService.cs

示例5: BeginConnect

 public IAsyncResult BeginConnect(string hostName, int port, AsyncCallback callback = null, object state = null)
 {
     var ar = new AsyncResult(state) { Hostname = hostName, Port = port };
     ar.Client = new TcpClient();
     ar.Client.BeginConnect(_info.ProxyHostname, _info.ProxyPort, OnConnected, ar);
     return ar;
 }
开发者ID:cyruslopez,项目名称:Floe,代码行数:7,代码来源:SocksTcpClient.cs

示例6: BeginDownloadXml

        public override IAsyncResult BeginDownloadXml(Uri feeduri, AsyncCallback callback)
        {
#if !WINDOWS_PHONE
            if (!IsolatedStorageFile.IsEnabled) throw new MissingFeedException("IsolatedStorage is not enabled! Cannot access files from IsolatedStorage!");
#endif


            try
            {
                using (var store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if(!PingFeed(feeduri, store)) throw new MissingFeedException(string.Format("Could not find feed at location {0}", feeduri));

                    using (var stream = new IsolatedStorageFileStream(feeduri.OriginalString, FileMode.Open,
                                                                   FileAccess.Read, store))
                    {
                        using(var reader = new StreamReader(stream))
                        {
                            var strOutput = reader.ReadToEnd();
                            //Fake the async result
                            var result = new AsyncResult<FeedTuple>(callback, new FeedTuple { FeedContent = strOutput, FeedUri = feeduri }, true);
                            if (callback != null) callback.Invoke(result);
                            return result;
                        }
                    }
                }
            }
            catch (IsolatedStorageException ex)
            {
                throw new MissingFeedException(string.Format("Unable to open feed at {0}", feeduri), ex);
            }
        }
开发者ID:GuiBGP,项目名称:qdfeed,代码行数:32,代码来源:IsolatedStorageFeedFactory.cs

示例7: BeginGetQuestionnaireTemplates

        public IAsyncResult BeginGetQuestionnaireTemplates(AsyncCallback callback, object asyncState)
        {
            var result = new AsyncResult<IEnumerable<QuestionnaireTemplate>>(callback, asyncState);
            HandleBeginGetQuestionnaireTemplates(result);

            return result;
        }
开发者ID:CarlosVV,项目名称:mediavf,代码行数:7,代码来源:MockQuestionnaireService.cs

示例8: WhenCreated_ThenIsNotComplete

        public void WhenCreated_ThenIsNotComplete()
        {
            var result = new AsyncResult<object>(null, this);

            Assert.IsFalse(result.IsCompleted);
            Assert.IsFalse(result.CompletedSynchronously);
        }
开发者ID:eslahi,项目名称:prism,代码行数:7,代码来源:AsyncResultFixture.cs

示例9: 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

示例10: BeginSubmitResponses

        public IAsyncResult BeginSubmitResponses(Questionnaire questionnaire, AsyncCallback callback, object asyncState)
        {
            var result = new AsyncResult<object>(callback, asyncState);
            HandleBeginSubmitResponses(result);

            return result;
        }
开发者ID:tian1ll1,项目名称:WPF_Examples,代码行数:7,代码来源:MockQuestionnaireService.cs

示例11: SetResult

    public void SetResult(AsyncResult asyncResult, object result)
    {
        lock (this._Lock)
        {
            List<TemporalAsyncResult> willRemovedTemporalAsyncResults = new List<TemporalAsyncResult>();
            DateTime now = DateTime.UtcNow;
            foreach(TemporalAsyncResult item in this._TemporalAsyncResults.Values)
            {
                if (now - item.TimeStamp > this._LiveTime)
                {
                    willRemovedTemporalAsyncResults.Add(item);
                }
            }
            foreach (TemporalAsyncResult item in willRemovedTemporalAsyncResults)
            {
                //AppDebug.LogEvent("AsyncResultManager.SetResult", string.Format("Delete timeout async result {0}, {1}", item.AsyncResult.Id, item.AsyncResult.MethodName), System.Diagnostics.EventLogEntryType.Information);

                this._Results.Remove(item.AsyncResult.Id);
                this._TemporalAsyncResults.Remove(item.AsyncResult.Id);
            }

            //AppDebug.LogEvent("AsyncResultManager.SetResult", string.Format("Set result of {0}, {1}", asyncResult.Id, asyncResult.MethodName), System.Diagnostics.EventLogEntryType.Information);
            this._Results.Add(asyncResult.Id, result);
            this._TemporalAsyncResults.Add(asyncResult.Id, new TemporalAsyncResult(asyncResult));
        }
    }
开发者ID:RobertHu,项目名称:TraderServer,代码行数:26,代码来源:AsyncResultManager.cs

示例12: Finally

 private static void Finally(AsyncResult result, Exception currentException)
 {
     SqlWorkflowInstanceStoreAsyncResult result2 = result as SqlWorkflowInstanceStoreAsyncResult;
     try
     {
         if (result2.DependentTransaction != null)
         {
             using (result2.DependentTransaction)
             {
                 result2.DependentTransaction.Complete();
             }
         }
     }
     catch (TransactionException)
     {
         if (currentException == null)
         {
             throw;
         }
     }
     finally
     {
         result2.OnCommandCompletion();
         result2.ClearMembers();
         StoreUtilities.TraceSqlCommand(result2.sqlCommand, false);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:27,代码来源:SqlWorkflowInstanceStoreAsyncResult.cs

示例13: WhenCompleted_ThenESetsResult

        public void WhenCompleted_ThenESetsResult()
        {
            var result = new AsyncResult<object>(null, null);

            result.SetComplete(this, true);

            Assert.AreSame(this, result.Result);
        }
开发者ID:eslahi,项目名称:prism,代码行数:8,代码来源:AsyncResultFixture.cs

示例14: BeginReceiveMessage

        public IAsyncResult BeginReceiveMessage(AsyncCallback asyncCallback, object state)
        {
            var asyncResult = new AsyncResult<string>(asyncCallback, state);

            ReturnMessageOrBeginReceive(asyncResult, true);

            return asyncResult;
        }
开发者ID:Cooke,项目名称:DotNetWebSocket,代码行数:8,代码来源:WebSocket.cs

示例15: BeginWrite

 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
 {
     //Console.WriteLine("SMS writing " + count + " bytes.");
     write = new AsyncResult() { AsyncState = state };
     Write(buffer, offset, count);
     callback(write);
     return write;
 }
开发者ID:nithinphilips,项目名称:bbwifimusicsync,代码行数:8,代码来源:SynchronousMemoryStream.cs


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