1
我想了解什么是IAsyncresult好,因此我写了这段代码。问题在于它的行为如同我称之为“MetodaAsync”的正常方式。在调试时,程序在此停止,直到方法完成。任何帮助表示感谢,谢谢。为什么我的异步调用不起作用?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
namespace ConsoleApplication1
{
class Program
{
delegate int Delegat();
static void Main(string[] args)
{
Program p=new Program();
Delegat d = new Delegat(p.MetodaAsync);
IAsyncResult a = d.BeginInvoke(null, null); //I have removed callback
int returned=d.EndInvoke(a);
Console.WriteLine("AAA");
}
private int MetodaAsync()
{
int AC=0;
for (int I = 0; I < 600000; I++)
{
for (int A = 0; A < 6000000; A++)
{
}
Console.Write("B");
}
return AC;
}
}
}
因此,如果它被阻塞,这里的异步性是什么?或者当我在Begin和EndIvoke之间做一些事情时,它会同时完成? – Petr 2010-04-30 07:48:54
@Petr:是的,它会同时执行。 – Henrik 2010-04-30 07:50:54