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 threadtest
{
public partial class MainPanel : Form
{
public Thread m_thread;
public MainPanel()
{
InitializeComponent();
}
private void threadBtn_Click(object sender, EventArgs e)
{
if((this.threadBtn.Text).Equals("启动")){
[color=red] m_thread = new Thread(new ThreadStart(Worker));[/color]
//传递的是一个线程的入口函数
m_thread.Start();
[color=red]Control.CheckForIllegalCrossThreadCalls = false;[/color]
//让控件能和线程交流
}
else{
m_thread.Abort();
this.threadBtn.Text = "启动";
}
}
private void Worker()
{
//for (int i = 0; i < 50;i++ )
int i = 0;
while(true)
{
this.threadBtn.Text = Convert.ToString(i);
Thread.Sleep(200);
i++;
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace threadtest
{
public partial class MainPanel : Form
{
public Thread m_thread;
public MainPanel()
{
InitializeComponent();
}
private void threadBtn_Click(object sender, EventArgs e)
{
if((this.threadBtn.Text).Equals("启动")){
[color=red] m_thread = new Thread(new ThreadStart(Worker));[/color]
//传递的是一个线程的入口函数
m_thread.Start();
[color=red]Control.CheckForIllegalCrossThreadCalls = false;[/color]
//让控件能和线程交流
}
else{
m_thread.Abort();
this.threadBtn.Text = "启动";
}
}
private void Worker()
{
//for (int i = 0; i < 50;i++ )
int i = 0;
while(true)
{
this.threadBtn.Text = Convert.ToString(i);
Thread.Sleep(200);
i++;
}
}
}
}