2013-05-21 29 views
3

我正在測試將運行在Azure Web角色中的SignalR應用程序。我有一個後臺處理線程,在WebRole的OnStart中創建。WebRole中的SignalR IHubContext任務

當我嘗試使用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應用程序的活着。

謝謝,丹尼爾

回答

0

我認爲,這與該webrole OnStart方法和Web應用程序是兩個不同的過程做。

+0

包含過程佈局的體系結構在http://blogs.msdn.com/b/kwill/archive/2011/05/05/windows-azure-role-architecture.aspx –