如何在多线程程序中处理窗口

时间:2015-06-18 13:46:00

标签: c# vsto

您好我正在为一个进程创建一个线程,在该进程中我正在尝试打开一个窗口但它打开并快速关闭。我能做什么来保持那个窗口并手动关闭

 private void supportCheckThread(object sender, RibbonControlEventArgs e)
    {
        ThreadObject thrdObj = new ThreadObject();
        thrdObj.sender = sender;
        thrdObj.e = e;

        try
        {
            thrCheckStart = new System.Threading.Thread(new ParameterizedThreadStart(createCheckThread));
            thrCheckStart.Start(thrdObj);              
        }
        catch (Exception ex) { 
        }
        finally { enableBtn(true); }
    }
    private void createCheckThread(object thrdParam)
    {
        ThreadObject ob = (ThreadObject)thrdParam;
        btncheck_Click(ob.sender, ob.e);           
    }
    private void newBtncheck_Click(object sender, RibbonControlEventArgs e)
    {
        enableBtn(false);
        supportCheckThread(sender, e);
        string s = "";
    }

这里我打开那个窗口

 h1 = new IDesignSpecWord2007.UI_Forms.HierarchyView(ref Globals.ThisAddIn.Application, ref docm);
                    h1.Show();

1 个答案:

答案 0 :(得分:0)

您应该仅将主线程用于UI任务。一旦代码/例程结束,就停止辅助线程。如果要始终显示表单,则需要无限期地保持辅助线程运行。当线程停止时,所有对象都被销毁并被扫除(因此,表单消失)。