LOOPC软件工作室

首页 » 技术文章 » 这个类很特别
amor - 2009/9/26 9:58:00
AsyncOperation asyncOperation;
SendOrPostCallback progressReporter;
Thread workerThread;

public MainForm()
{
    InitializeComponent();

    asyncOperation = AsyncOperationManager.CreateOperation(null);
    progressReporter = new SendOrPostCallback(ReportProgress);
    workerThread = new Thread(new ThreadStart(WorkOnWorkerThread));
}

private void MainForm_Load(object sender, EventArgs e)
{
    Thread.CurrentThread.Name = "Main Thread";
    workerThread.Name = "Worker Thread";
    workerThread.IsBackground = true;
    workerThread.Start();
}

void ReportProgress(object obj)
{
    this.Text = obj.ToString() + "% - " + Thread.CurrentThread.Name;
}

void WorkOnWorkerThread()
{
    int i = 0;
    while (i++ < 100)
    {
        asyncOperation.Post(progressReporter, i);
        Thread.Sleep(50);
    }
}
huajiante - 2009/11/13 18:19:00
不懂
1
查看完整版本: 这个类很特别