使用相关的具备条件:
1.前提是必须窗体实例完毕,再触发相关事件开始调用
2.代码如下:如在窗体加载完毕的一个button事件调用线程1
Thread th1= new Thread(new ThreadStart(process1));
th1.Start();
//开始调用线程
private void process1()
{
while (true)
{
Thread.Sleep(Convert.ToInt32(sleepTime));//设置延迟时间
Thread th3 = new Thread(new ThreadStart(process3));//刷新任务
th3.Start();
}
}
//具体使用BeginInvoke方法调用窗体
private void process3()
{
MethodInvoker mi = new MethodInvoker(this.ShowMsgForm);
this.BeginInvoke(mi);
}
窗体实例亦可分为两种情况
1.直接实例化
private void ShowMsgForm()
{
ArasUpboxNews setNews = new ArasUpboxNews();//实例窗体
setNews.Show(this);
}
2.判断窗体是否存在的实例
private void ShowMsgForm()
{
ArasUpboxNews setNews = ArasUpboxNews.getinstance();
if (!setNews .Visible)
{
setNews .Show(this);
}
}
3.在ArasUpboxNews窗体中判定窗体是否显示
private static ArasUpboxNews _initialize = null;
//初始化窗体
public static ArasUpboxNews getinstance()
{
if (_initialize == null)
{
_initialize = new ArasUpboxNews();
}
return _initialize;
}
注意:实例之后一般要用this.Hide();属性
在form_closed事件中 写入_initalize = null;
如:private void form_FormClosed(object sender, FormClosedEventArgs e)
{
_initialize = null;
}
在form_closing事件中 写入this.Hide();
如:private void form_FormClosing(object sender, FormClosingEventArgs e)
{
this.Hide();
}