您的位置:首页 > 编程语言 > C#

c# 事件用法2

2012-12-18 11:39 253 查看
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
Thread thread = new Thread(test_show);
thread.IsBackground = true;
thread.Start();
}

private void button2_Click(object sender, EventArgs e)
{
Thread thread = new Thread(DownloadInWhData);
thread.IsBackground = true;
thread.Start();
}
void test_show()
{

while (true)
{
Console.WriteLine("runing test_show");
Thread.Sleep(4000);

}

}

public void DownloadInWhData()
{
this.Invoke((EventHandler)(delegate
{
while (true)
{
Console.WriteLine("runing delegate");
Thread.Sleep(6000);

}
}));
}
}


按钮2执行的线程会同步等待这个线程运行完,按钮1不会。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: