2010-09-01 137 views
0

我正在为Rhino开发一个插件,当我运行启动插件的命令时,我执行以下操作。它创建一个飞溅形式,其上有一个定时器,2秒后我加载另一个表单。如何检查表单的实例是否已经存在?

如果我错误地再次单击插件图标,它会创建另一个spash窗体的实例,它将再次加载插件。

我该如何预防?

这是制作窗体的代码。

public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) 
      { 

       Splash Splash = new Splash(); 
       Splash.Show(); 

       return IRhinoCommand.result.success; 
      } 

回答

4
public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) 
{ 
    if (!Application.OpenForms.OfType<Splash>().Any()) 
    { 
     new Thread(() => Application.Run(new Splash())).Start(); 
    } 
    return IRhinoCommand.result.success; 
} 
+0

当我尝试使用它通过System.Windows.Forms的它无法找到OfType财产,我如何使用它? – Bildsoe 2010-09-01 13:37:17

+0

@Bildsoe:如果您使用的是.NET 3.5或更高版本,请确保在文件顶部有'System.Core'引用和'using System.Linq;'指令。如果你不是,循环“Application.OpenForms”并检查是否有任何窗体是'Splash'对象。 – Ani 2010-09-01 13:49:49

+0

当它作为一个线程运行时,我该如何做Splash.show? – Bildsoe 2010-09-01 14:00:42

相关问题