SignalR,Outlook加载项和多线程异常 [英] SignalR, Outlook add-in and multithread exception

查看:118
本文介绍了SignalR,Outlook加载项和多线程异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Outlook中,我有此代码...

In Outlook I have this code...

_connection = New HubConnection(Me._url)
_connection.Credentials = CredentialCache.DefaultCredentials
_hub = _connection.CreateHubProxy(Me._hubName)
_hub.On(Of String)("NewMessage", Function(message)
                                     Dim f As New TestForm
                                     f.Show()
                                     Return ""
                                 End Function)

_connection.Start()

但是显示我的表单"TestForm"会崩溃,因为它在主线程中,而SignalR在另一个线程中.

But showing my form "TestForm" crashes since its in the main thread and SignalR is on another thread.

有什么想法可以使它起作用吗?

Any idea how I can make it work?

推荐答案

您的最佳尝试是使用专用线程来执行SignalR作业,并重新使用STA主线程来访问Outlook对象模型或显示表单/WPF.组件.

Your best attempt would be to use a dedicated thread to do your SignalR jobs and get back on the main STA thread for accessing Outlook Object Model or displaying forms/WPF components.

这是如何在主线程上继续"工作的方法: 挂钩事件Outlook VSTO在主线程上继续工作

This how you can "continue" your work on the main thread: Hooked events Outlook VSTO continuing job on main Thread

这篇关于SignalR,Outlook加载项和多线程异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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