本文整理汇总了C#中BinaryOp.EndInvoke方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryOp.EndInvoke方法的具体用法?C# BinaryOp.EndInvoke怎么用?C# BinaryOp.EndInvoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryOp
的用法示例。
在下文中一共展示了BinaryOp.EndInvoke方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
Console.WriteLine("***** Async Delegate Invocation *****");
// Print out the ID of the executing thread.
Console.WriteLine("Main() invoked on thread {0}.",
Thread.CurrentThread.ManagedThreadId);
BinaryOp b = new BinaryOp(Add);
IAsyncResult iftAR = b.BeginInvoke(10, 10, null, null);
// This message will keep printing until
// the Add() method is finished.
while (!iftAR.IsCompleted)
{
Console.WriteLine("Doing more work in Main()!");
Thread.Sleep(1000);
}
// Now we know the Add() method is complete.
int answer = b.EndInvoke(iftAR);
Console.WriteLine("10 + 10 is {0}.", answer);
Console.ReadLine();
}
示例2: Main
static void Main(string[] args)
{
Console.WriteLine("***** AsyncCallbackDelegate Example *****");
Console.WriteLine("Main() invoked on thread {0}.",
Thread.CurrentThread.ManagedThreadId);
BinaryOp b = new BinaryOp(Add);
IAsyncResult iftAR = b.BeginInvoke(10, 10,
new AsyncCallback(AddComplete),
"Main() thanks you for adding these numbers.");
// Assume other work is performed here...
while (!isDone)
{
Thread.Sleep(1000);
Console.WriteLine("Working....");
}
// BeginInvoke / EndInvoke
IAsyncResult asyncResult = b.BeginInvoke(8, 7, null, null);
int result1 = b.EndInvoke(asyncResult);
Console.WriteLine("{0}", result1);
// System.Threading.Tasks.Task
Task task = null;
task = Task.Factory.StartNew(() =>
{
b.BeginInvoke(9, 9, null, null);
int result2 = b.EndInvoke(asyncResult);
Console.WriteLine("{0}", result2);
});
while (task.Status == TaskStatus.Running)
{
// wait
}
// System.Threading.Tasks.Parallel
Parallel.Invoke(() => Add(3, 4), () => Add(3, 4), () => Add(3, 4));
Console.ReadLine();
}
示例3: AsyncDelegate
public static void AsyncDelegate()
{
Console.WriteLine("AsyncDelegate() on thread Id: {0}", Thread.CurrentThread.ManagedThreadId);
BinaryOp b = new BinaryOp(Add);
IAsyncResult iar = b.BeginInvoke(1, 2, null, null);
//while (!iar.IsCompleted) {
// Console.WriteLine("doing more foreground work...");
// Thread.Sleep(1000);
//}
while (!iar.AsyncWaitHandle.WaitOne(1000, true)) {
Console.WriteLine("doing more foreground work...");
}
int z = b.EndInvoke(iar);
Console.WriteLine("AsyncDelegate() z = {0}", z);
}
示例4: AsyncCall
static void AsyncCall()
{
Console.WriteLine("***** Async Delegate Review *****");
// Print out the ID of the executing thread.
Console.WriteLine("Main() invoked on thread {0}.",
Thread.CurrentThread.ManagedThreadId);
// Invoke Add() in a asynchronous manner.
// but it is still synchronous call.
BinaryOp b = new BinaryOp(Add);
IAsyncResult res = b.BeginInvoke(10, 10, null, null);
Console.WriteLine("Doing more work in Main()!");
//Obtain results from Add
int answer = b.EndInvoke(res);
Console.WriteLine("10 + 10 is {0}.", answer);
}
示例5: Main
public static void Main (string[] args)
{
Console.WriteLine ("** Sync Delegate Review **");
Console.WriteLine ("Main() invoked on thread {0}", Thread.CurrentThread.ManagedThreadId);
BinaryOp b = new BinaryOp (Add);
IAsyncResult iftAR = b.BeginInvoke (10, 10, null, null);
// int answer = b(10, 10);
while (!iftAR.IsCompleted)
{
Console.WriteLine("Doing more work in Main()");
Thread.Sleep(1000);
}
int answer = b.EndInvoke(iftAR);
// Console.WriteLine("Doing more work in main()");
Console.WriteLine("10 + 10 is {0}", answer);
Console.ReadLine();
}
示例6: Main
static void Main(string[] args)
{
Console.WriteLine("***** Async Delegate Invocation *****");
// Print out the ID of the executing thread.
Console.WriteLine("Main() invoked on thread {0}.",
Thread.CurrentThread.ManagedThreadId);
// Invoke Add() on a secondary thread.
BinaryOp b = new BinaryOp(Add);
IAsyncResult iftAR = b.BeginInvoke(10, 10, null, null);
// Do other work on primary thread...
Console.WriteLine("Doing more work in Main()!");
// Obtain the result of the Add()
// method when ready.
int answer = b.EndInvoke(iftAR);
Console.WriteLine("10 + 10 is {0}.", answer);
Console.ReadLine();
}
示例7: UseBeginInvoke
private void UseBeginInvoke(BinaryOp binOp, int x, int y)
{
IAsyncResult asyncRes = binOp.BeginInvoke(x, y, null, null);
//RunWaitHandle(asyncRes);
RunIsCompletedCall(asyncRes);
int answer = binOp.EndInvoke(asyncRes);
Console.WriteLine("{0} + {1} = {2}", x, y, answer);
}
示例8: AsyncTest
private static void AsyncTest()
{
Console.WriteLine("***** Async Delegate Review");
// Print out the ID of the executing thread.
Console.WriteLine("Main() invoked on thread {0}", Thread.CurrentThread.ManagedThreadId);
// Invoke Add() in a secondary thread.
BinaryOp b = new BinaryOp(Add);
IAsyncResult iftAR = b.BeginInvoke(10, 10, null, null);
// Do other work on primary thread..
// This call takes far less than five seconds
// because of async
while (!iftAR.AsyncWaitHandle.WaitOne(1000,true))
{
Console.WriteLine("Doing more word in Main()!");
}
// Obtain the result of the Add();
// Now we are waiting again for other thread to compelte
int answer = b.EndInvoke(iftAR);
Console.WriteLine("10 + 10 is {0}", answer);
Console.ReadLine();
}
示例9: WaitCall
static void WaitCall()
{
Console.WriteLine("***** Async Delegate Review *****");
// Print out the ID of the executing thread.
Console.WriteLine("Main() invoked on thread {0}.",
Thread.CurrentThread.ManagedThreadId);
// Invoke Add() in a asynchronous manner.
BinaryOp b = new BinaryOp(Add);
IAsyncResult res = b.BeginInvoke(10, 10, null, null);
//while (!res.IsCompleted)
//{
// Console.WriteLine("Doing more work in Main()!");
// Thread.Sleep(1000);
//}
while (!res.AsyncWaitHandle.WaitOne(1000, true))
{
Console.WriteLine("Doing more work in Main()!");
}
//Obtain results from Add
int answer = b.EndInvoke(res);
Console.WriteLine("10 + 10 is {0}.", answer);
}