日期:2014-05-17 浏览次数:20944 次
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private static bool threadSwitch = false;//定义一个全局变量来控制线程
private void button1_Click(object sender, EventArgs e)
{
if (button1.Text == "继续")
{//开始
button1.Text = "暂停";
threadSwitch = true;
ThreadPool.QueueUserWorkItem(h =>
{//在这里执行线程工作
while (threadSwitch == true)
{
textBox1.Invoke(new Action(delegate
{
textBox1.Text = DateTime.Now.ToString();
}));
}
&n