Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

呼出插件窗口

Mr.喜 edited this page Aug 16, 2020 · 3 revisions

与前一页调用插件事件是一个方法,调用插件的menu函数即可
此程序呼出窗口使用托盘右键呼出菜单,托盘使用WinFormNotifyIcon实现,代码在这里

注意事项

主控制台的主线程中需要不断刷新此UI线程,否则会出现托盘右键无法呼出的情况

while(true)
{
    Thread.Sleep(100);
    Application.DoEvents();
}

WPF窗口的线程问题

插件的窗口回调事件内尝试将实例化窗口的代码替换为下面这些,我自己尝试过是有效的

try
{
    if (window == null)
    {
        Thread thread = new Thread(() =>
        {
            window = new MainWindow();
            window.Closing += Window_Closing;
            window.ShowDialog();
        });
        thread.SetApartmentState(ApartmentState.STA);
        thread.Start();                    
    }
    else
    {
        window.Activate();
    }
}
catch(Exception exc)
{
    CQSave.cqlog.Info("Error",exc.Message,exc.StackTrace);
}