protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
Thread checkMsgBoxThread = new Thread(RefreshMsgBoxTopmost);
checkMsgBoxThread.Start();
}
private void RefreshMsgBoxTopmost()
{
if (this.InvokeRequired == false)
{
SetMsgBoxTopmost();
}
else
{
SetMsgBoxTopmostDelegate setMsgBoxTopmostDelegate = new SetMsgBoxTopmostDelegate(SetMsgBoxTopmost);
this.BeginInvoke(setMsgBoxTopmostDelegate, null);
}
}
private void SetMsgBoxTopmost()
{
while (true)
{
foreach (Form frm in XconMessageBox.FormList)
{
frm.TopMost = true;
}
Thread.Sleep(2000);
}
}
代码没什么特别的。
解决方案 »
- 同时读串口的问题,急 啊
- NPOI在Excel中画竖线
- xp下c#网站能运行,win7下却不行,错误如下:
- c#小白问个关于api函数对应.net的问题
- 问个C# 读出内存地址后,这么显示游戏怪物名字的问题
- 大家帮我看看 以我这中水平在深圳能拿到多少!
- c#如何调用C++ DLL中的方法,入参是一个struct的指针
- 怎样在打开的Excel中调用这个Excel里的某个宏?
- 如何打开vs2005中的server explorer
- BindingList<T>集合Remove(T)的时候, 出现提供的行索引超出范围异常
- C# 网页接收数据 并返回数据??
- devexpress.xtragrid.gridcontrol 修改单元格的编辑内容,但是会因为光标的变换,数据会消失
{
foreach (Form frm in XconMessageBox.FormList)
{
frm.TopMost = true;
}
Thread.Sleep(2000);
}
这还不特别吗?
你既然知道定义委托,线程里怎么不调用委托呢,为什么要直接操作窗体?
有while的部分应该定义成线程,而赋值的部分定义成委托
你在委托函数里调用while,不卡死了
void SetMsgBoxTopmost()
{
if (this.InvokeRequired)
{
SetMsgBoxTopmostDelegate setMsgBoxTopmostDelegate = new SetMsgBoxTopmostDelegate(SetMsgBoxTopmost);
this.BeginInvoke(setMsgBoxTopmostDelegate, null);
}
else
{
foreach (Form frm in XconMessageBox.FormList)
{
frm.TopMost = true;
}
}
}这里是递归调用
先在线程里调用,判断它是需要Invork的,则执行Invork通知主线程来调用自身
然后主线程调用,判断不需要Invork,直接执行foreach赋值