本文整理汇总了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;
}
示例2: BeginGetQuestionnaireTemplateSummary
public IAsyncResult BeginGetQuestionnaireTemplateSummary(QuestionnaireTemplate questionnaireTemplate, AsyncCallback callback, object asyncState)
{
var result = new AsyncResult<QuestionnaireTemplateSummary>(callback, asyncState);
HandleBeginGetQuestionnaireTemplateSummary(result);
return result;
}
示例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;
}
示例4: BeginGetQuestionnaire
public IAsyncResult BeginGetQuestionnaire(AsyncCallback callback, object asyncState)
{
var result = new AsyncResult<Questionnaire>(callback, asyncState);
HandleBeginGetQuestionnaire(result);
return result;
}
示例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;
}
示例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);
}
}
示例7: BeginGetQuestionnaireTemplates
public IAsyncResult BeginGetQuestionnaireTemplates(AsyncCallback callback, object asyncState)
{
var result = new AsyncResult<IEnumerable<QuestionnaireTemplate>>(callback, asyncState);
HandleBeginGetQuestionnaireTemplates(result);
return result;
}
示例8: WhenCreated_ThenIsNotComplete
public void WhenCreated_ThenIsNotComplete()
{
var result = new AsyncResult<object>(null, this);
Assert.IsFalse(result.IsCompleted);
Assert.IsFalse(result.CompletedSynchronously);
}
示例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;
}
示例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));
}
}
示例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);
}
示例14: BeginReceiveMessage
public IAsyncResult BeginReceiveMessage(AsyncCallback asyncCallback, object state)
{
var asyncResult = new AsyncResult<string>(asyncCallback, state);
ReturnMessageOrBeginReceive(asyncResult, true);
return asyncResult;
}
示例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;
}