this.BeginInvoke(new System.Threading.ThreadStart(delegate()
{
lblCount.Text = count.ToString();
}));
调试到这里看到的错误提示:不能进入 lblCount.Text = count.ToString();
{
lblCount.Text = count.ToString();
}));
调试到这里看到的错误提示:不能进入 lblCount.Text = count.ToString();
How to update the GUI from another thread in C#?
http://stackoverflow.com/questions/661561/how-to-update-the-gui-from-another-thread-in-c
将定时调用放到线程中就好了,修改代码如下:
private void btnIPCrawl_Click(object sender, EventArgs e)
{
Thread thread = new Thread(TimerCrawlIP);
thread.IsBackground = true;
thread.Start();
} /// <summary>
/// 定时抓取IP
/// </summary>
private void TimerCrawlIP()
{
//隔段时间自动调用程序
System.Threading.Timer threadTimer = new System.Threading.Timer(new System.Threading.TimerCallback(InvokeIPCrawl), null, 0, 14400000);
while (true)
{
Thread.Sleep(14400000);
}
}