SignalR を使用する例がたくさんあることは知っていますが、それを機能させることができないようです。あなたの 1 人が (完全に) WebPage (スレッド化されたループを見ることができるように) を示すことができることを望んでいました何度も発生します) Page で JS メソッドを呼び出して、テキスト ラベルを変更したり、ポップアップを作成したり、メソッドの実行を確認できるようにするだけでしょうか?
私はあなたに私のコードを提供し、エラーを指摘できるかもしれませんが、クライアントが最初にリクエストを行わずに Server->Client を呼び出す基本的な例は素晴らしいでしょう!
ハブ:
[HubName("chat")]
public class Chat : Hub
{
public void Send(string message)
{
// Call the addMessage method on all clients?
Clients.addMessage(message);
}
}
呼び出し (スレッド) メソッド:
private void DoIt()
{
int i = 0;
while (true)
{
var hubContext = GlobalHost.ConnectionManager.GetHubContext<Chat>();
hubContext.Clients.addMessage("Doing it... " + i);
i++;
Thread.Sleep(500);
}
}
JS:
$(function () {
// Proxy created on the fly
var chat = $.connection.chat;
// Declare a function on the chat hub so the server can invoke it
chat.addMessage = function (message) {
confirm("Are you having fun?");
confirm(message);
};
// Start the connection
$.connection.hub.start();
});