我今天做了一个小测试,以了解有关BackgroundWorker的更多信息.
在我看来,它不适用于asychronuos模式.首先它做了Do1和下一个Do2.Do2更短,Do1需要更多时间,但是程序等待Do1完成并且下一次启动Do2.我对吗?谢谢!
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Transactions;
namespace ConsoleApplication16
{
public interface I
{
void UstawWiek(string w);
void PokazWiek();
}
class rrr
{
public delegate void MojDelegat();
public static void Do1(object sender, DoWorkEventArgs e)
{
System.Threading.Thread.Sleep(4000);
Console.WriteLine("Do1");
}
public static void Do2(object sender, DoWorkEventArgs e)
{
System.Threading.Thread.Sleep(1000);
Console.WriteLine("Do2");
}
static void Main(string[] args)
{
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += new DoWorkEventHandler(Do1);
bw.DoWork += …Run Code Online (Sandbox Code Playgroud)