VSTO WPF展望外接程序 - 随机场合不响应的用户界面 [英] VSTO WPF Outlook Addin - Unresponsive UI at random occasions

查看:200
本文介绍了VSTO WPF展望外接程序 - 随机场合不响应的用户界面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个VSTO插件的Outlook 2007中使用.NET 4.0开发WPF。一位PC的地方得到了部署,正在和UI的问题。在某些场合UI变得没有反应几分钟。点击不起作用。片刻之后一切变得恢复正常,用户可以点击按钮。
安装在PC上的其他加载项是 - 。SNAGIT和谷歌桌面的Outlook工具栏

We have a VSTO addin for Outlook 2007 developed using .Net 4.0 WPF. One of the PC where it got deployed, is having an issue with UI. At some occasions UI becomes unresponsive for few moments. Clicks does not work. After few moments everything gets back to normal and user can click the buttons. Other addins installed on the PC are - SnagIT and Google Desktop Outlook Toolbar.

请帮助我们,如果您有此类问题的任何输入

Please help us if you have any input on this kind of issue.

推荐答案

我曾与一个Word加载同样的问题 - 在一个非常结实的开发商箱 - 用户界面只会锁定即使我在做我在后台的所有工作。

I had the same issue with a Word Add-In -- on a very beefy developer box -- the UI would just lock up even though I was doing all my work in the background.

我的理论是,这个词是在UI线程上做的工作,即使我是从后台线程等调用它

My theory is that Word was doing work on the UI thread even though I was invoking it from background threads, etc.

我试过一个实验 - 实例化一个新的线程Window对象(即让自己的UI线程不是同一个线程Word的工作线程) - 和有效。我的UI不再在随机时间间隔锁定。

I tried an experiment -- instantiating the Window object on a new Thread (i.e. so that my UI thread is not the same thread as Word's worker thread) -- and it worked. My UI no longer locks up at random intervals.

请小心你的线程关闭前摆脱COM对象的任何实例,并特别小心的跨线程COM访问(可能使用Dispatcher.Invoke回Office应用程序主机的线程访问任何的RCW时... - 调度员与他们实例化的线程相关的,所以你只需要实例化办公室主应用程序的调度程序回调,等...)

Be careful to get rid of any instances of COM objects before your thread closes, and especially careful of cross-thread COM access (potentially using Dispatcher.Invoke back to the Office host app's thread when accessing any of its RCWs... -- Dispatchers are associated with the threads they're instantiated on, so you would just have to instantiate a dispatcher in the office host app's callback, etc...)

注意:如果您Dispatcher.Invoke回调用线程,则不能使用的Thread.join如下所示。 (在这种情况下,你需要处理应用程序事件,Thread.sleep代码和Thread.Yield)在一个繁忙的循环。否则,你会得到一个僵局

Note: If you Dispatcher.Invoke back to the calling thread, you can't use Thread.Join as shown below. (In that case, you would need to handle application events, Thread.Sleep, and Thread.Yield) in a busy loop. Otherwise, you'll get a deadlock.

下面是我在做什么的泛型化版本,例如:

Here's a genericized example version of what I'm doing:

// This approach makes WPF Windows an order of magnitude more responsive
Thread t = new Thread(() =>
{
    try
    {
        // Implement the IDisposable pattern on your window to release
        //   any resources before the thread exits
        using (var myWindow = new MyWindow())
        {
            // Do any other pre-display initialization with the myWindow
            //   object here...

            myWindow.ShowDialog();
        }
    }
    finally
    {
        // Strongly Recommended (not doing this may cause
        //   weird exceptions at application shutdown):
        Dispatcher.CurrentDispatcher.InvokeShutdown();
    }
});

t.SetApartmentState(ApartmentState.STA); // Required
t.IsBackground = false; // Recommended

t.Start(); // Kicks off the new UI thread
t.Join();  // Blocks execution until the new UI thread has finished executing...

这篇关于VSTO WPF展望外接程序 - 随机场合不响应的用户界面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆