3

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 アプリケーションを維持することに戻ります。

ありがとう、ダニエル

4

1 に答える 1

0

I think, this has to do with the webrole OnStart method and the web applications being two different processes.

于 2014-02-26T18:31:00.707 に答える