level 1
天草緋鞠
楼主
如题 我写1个执行绪
程式:
class SysHelper
{
public static TextBox _textbox;
delegate void PrintHandler(TextBox tb,string text);
public static void Run()
{
int x = 0;
while (true)
{
if (x % 1000 == 0)
{
Print(_textbox, x.ToString());
}
x++;
}
}
public static void Print(TextBox tb,string text)
{
if (tb.InvokeRequired)
{
PrintHandler ph = new PrintHandler(Print);
tb.Invoke(ph, tb,text);
}
else
{
tb.Text = tb.Text + text + Environment.NewLine;
}
}
}
public partial class Form1 : Form
{
Thread othread;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SysHelper._textbox = textBox1;
othread = new Thread(SysHelper.Run);
othread.Start();
}
private void button2_Click(object sender, EventArgs e)
{
othread.Abort();
}
}
已经能正常工作
但是遇到一个很诡异的问题
点击视窗边框(会出现可拉长的)或标题(titlebar)
执行序回停住 滑鼠放开之后又继续正常印出
请问这个问题有什么可以解决的方法吗?
2016年02月20日 12点02分
1
程式:
class SysHelper
{
public static TextBox _textbox;
delegate void PrintHandler(TextBox tb,string text);
public static void Run()
{
int x = 0;
while (true)
{
if (x % 1000 == 0)
{
Print(_textbox, x.ToString());
}
x++;
}
}
public static void Print(TextBox tb,string text)
{
if (tb.InvokeRequired)
{
PrintHandler ph = new PrintHandler(Print);
tb.Invoke(ph, tb,text);
}
else
{
tb.Text = tb.Text + text + Environment.NewLine;
}
}
}
public partial class Form1 : Form
{
Thread othread;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
SysHelper._textbox = textBox1;
othread = new Thread(SysHelper.Run);
othread.Start();
}
private void button2_Click(object sender, EventArgs e)
{
othread.Abort();
}
}
已经能正常工作
但是遇到一个很诡异的问题
点击视窗边框(会出现可拉长的)或标题(titlebar)
执行序回停住 滑鼠放开之后又继续正常印出
请问这个问题有什么可以解决的方法吗?