1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
public
partial
class
UCInfo : UserControl
{
public
UCInfo()
{
InitializeComponent();
}
ManualResetEvent neverSetEvt =
new
ManualResetEvent(
false
);
delegate
void
InvokeDelegate();
public
void
SetInfo(
string
info)
{
lblInfo.Invoke(
new
InvokeDelegate(() => { lblInfo.ForeColor = Color.Green; }),
null
);
lblInfo.Invoke(
new
InvokeDelegate(() => { lblInfo.Text = info; }),
null
);
ThreadPool.RegisterWaitForSingleObject(neverSetEvt, (obj, bol) =>
{
if
(lblInfo.IsHandleCreated)
{
lblInfo.Invoke(
new
InvokeDelegate(() => { lblInfo.Text =
""
; }),
null
);
}
},
null
, 600000,
true
);
}
public
void
SetInfo(
string
info, Color color)
{
lblInfo.Invoke(
new
InvokeDelegate(() => { lblInfo.ForeColor = color; }),
null
);
lblInfo.Invoke(
new
InvokeDelegate(() => { lblInfo.Text = info; }),
null
);
ThreadPool.RegisterWaitForSingleObject(neverSetEvt, (obj, bol) =>
{
if
(lblInfo.IsHandleCreated)
{
lblInfo.Invoke(
new
InvokeDelegate(() => { lblInfo.Text =
""
; }),
null
);
}
},
null
, 600000,
true
);
}
}<br><br>当调试运行中突然关闭软件时,
|
1
|
lblInfo.Invoke(labchange);语句就出先了“在创建窗口句柄之前,不能在控件上调用 Invoke 或 BeginInvoke。”错误。<br>解决办法是在lblInfo.Invoke(labchange);前加一个
if
(lblInfo.IsHandleCreated)判断就可以了
|
本文转自94cool博客园博客,原文链接:http://www.cnblogs.com/94cool/p/3904076.html,如需转载请自行联系原作者