不知道异步与多线程是啥关系,感觉效果都是一样的呀?
如下两段程序,效果一样:
1.异步:
delegate void ProcessDelegate();
private void Process()
{
for(int i=0;i<90000000;i++);
}
private void do()
{
ProcessDelegate pdSteps = new ProcessDelegate(Process);
pdSteps.BeginInvoke(null, null);
}
2.多线程:
private void Process()
{
for(int i=0;i<90000000;i++);
}
private void do()
{
System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(Process));
t.Start();
}
如下两段程序,效果一样:
1.异步:
delegate void ProcessDelegate();
private void Process()
{
for(int i=0;i<90000000;i++);
}
private void do()
{
ProcessDelegate pdSteps = new ProcessDelegate(Process);
pdSteps.BeginInvoke(null, null);
}
2.多线程:
private void Process()
{
for(int i=0;i<90000000;i++);
}
private void do()
{
System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ThreadStart(Process));
t.Start();
}
for (int i = 0; i < 90000000; i++) Application.DoEvents() ;