我正在测试一个将在Azure Web角色中运行的SignalR应用程序。我有一个后台处理线程,是在WebRole的OnStart中创建的。
当我尝试使用IHubContext发送组消息时,它失败了,没有任何错误-集线器客户端从未接收到该消息。从Global.asax内部创建的相同代码将正常运行。
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports Microsoft.WindowsAzure
Imports Microsoft.WindowsAzure.Diagnostics
Imports Microsoft.WindowsAzure.ServiceRuntime
Imports Microsoft.AspNet.SignalR
Imports System.Threading.Tasks
Public Class WebRole
Inherits RoleEntryPoint
Public Overrides Function OnStart() As Boolean
Task.Factory.StartNew(Sub() AsyncTaskTest())
Return MyBase.OnStart()
End Function
Private Sub AsyncTaskTest()
Do
Threading.Thread.Sleep(10000)
Dim Context As IHubContext = GlobalHost.ConnectionManager.GetHubContext(Of Testub)()
Context.Clients.Group("testgroup").Message("This is a delayed message from the WebRole thread.")
Loop
End Sub
End Class是否可以以这种方式使用IHubContext?这是否算作一个单独的程序集,并且需要使用HubConnection?如果我不能使用IHubContext,我将恢复到在Global.asax中使用它,并保持web应用程序的活动状态。
谢谢,丹尼尔
发布于 2014-02-27 02:31:01
我认为,这与webrole OnStart方法和web应用程序是两个不同的过程有关。
https://stackoverflow.com/questions/16666793
复制相似问题