本文整理汇总了C#中AsyncCallback.?.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# AsyncCallback.?.Invoke方法的具体用法?C# AsyncCallback.?.Invoke怎么用?C# AsyncCallback.?.Invoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AsyncCallback
的用法示例。
在下文中一共展示了AsyncCallback.?.Invoke方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BeginConnectProxy
public void BeginConnectProxy(EndPoint remoteEP, AsyncCallback callback, object state)
{
// do nothing
var r = new FakeAsyncResult(state);
callback?.Invoke(r);
}
示例2: ToBegin
/// <summary>
///
/// </summary>
/// <param name="task"></param>
/// <param name="callback"></param>
/// <param name="state"></param>
/// <returns></returns>
public static IAsyncResult ToBegin(Task task, AsyncCallback callback, object state)
{
if (task == null)
throw new ArgumentNullException(nameof(task));
var tcs = new TaskCompletionSource<object>(state);
task.ContinueWith(t =>
{
if (task.IsFaulted)
{
if (task.Exception != null)
tcs.TrySetException(task.Exception.InnerExceptions);
}
else if (task.IsCanceled)
{
tcs.TrySetCanceled();
}
else
{
tcs.TrySetResult(null);
//tcs.TrySetResult(RpcAction.GetTaskResult(t));
}
callback?.Invoke(tcs.Task);
}/*, TaskScheduler.Default*/);
return tcs.Task;
}
示例3: ToBegin
/// <summary>
/// Wraps a <see cref="Task"/> into the Begin method of an APM pattern.
/// </summary>
/// <param name="task">The task to wrap.</param>
/// <param name="callback">The callback method passed into the Begin method of the APM pattern.</param>
/// <param name="state">The state passed into the Begin method of the APM pattern.</param>
/// <returns>The asynchronous operation, to be returned by the Begin method of the APM pattern.</returns>
public static IAsyncResult ToBegin(Task task, AsyncCallback callback, object state)
{
var tcs = new TaskCompletionSource(state);
task.ContinueWith(t => {
tcs.TryCompleteFromCompletedTask(t);
callback?.Invoke(tcs.Task);
}, TaskScheduler.Default);
return tcs.Task;
}
示例4: LazyAsyncResult
public LazyAsyncResult(SslState sslState, object asyncState, AsyncCallback asyncCallback)
{
AsyncState = asyncState;
asyncCallback?.Invoke(this);
}
示例5: BeginRead
/// <summary>
/// Begins and asynchronous read of the specified stream
/// </summary>
/// <param name="stream">The stream.</param>
/// <param name="buffer">The buffer.</param>
/// <param name="offset">The offset.</param>
/// <param name="count">The count.</param>
/// <param name="callback">The callback.</param>
/// <param name="state">The state.</param>
/// <returns></returns>
public static IAsyncResult BeginRead(this Stream stream, byte[] buffer,
int offset,
int count,
AsyncCallback callback,
object state)
{
var result = new AsyncResult(state);
Task.Run(() =>
{
try
{
var data = stream.Read(buffer, offset, count);
result.Complete(data);
callback?.Invoke(result);
}
catch (IOException)
{
// Ignore, possible connection closed
}
});
return result;
}
示例6: BeginWrite
public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
{
Write(buffer, offset, count);
var tcs = new TaskCompletionSource<object>(state);
tcs.TrySetResult(null);
IAsyncResult result = tcs.Task;
callback?.Invoke(result);
return result;
}