SignalR, Outlook add-in and multithread exception

痴心易碎 提交于 2019-12-13 01:25:30

问题


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()

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?


回答1:


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.

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



来源:https://stackoverflow.com/questions/35057480/signalr-outlook-add-in-and-multithread-exception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!