我試圖從服務器調用客戶端和一個字符串傳遞到客戶端的功能或文本添加到客戶端文本框 - 沒有什麼作品,代碼運行,但沒有任何反應(該客戶端連接到服務器沒有問題)是什麼問題?謝謝。 //服務器SignalR不火的客戶端的功能
class Hub:hub
{
public void sendClientIdToServer()
{
Clients.Caller.getFeedBack("hey");
}
}
//客戶
private async void connectToServer()
{
Connection = new HubConnection(LocalClient);
HubProxy = Connection.CreateHubProxy("ConnectByHub");
//try to call another function and pass to the function a string.
HubProxy.On("getFeedBack", (msg) => Invoke((Action)(() => { getFeedBack(msg); })));
// try to add text to richTextBox
HubProxy.On<string>("getFeedBack", (msg) => Invoke((Action)(() => { MsgTxtBox.Text = msg; })));
try
{
await Connection.Start();
}
catch (Exception ex)
{
Invoke((Action)(() => { connectStat.Text = "Error Not connected"; }));
return;
}
Invoke((Action)(() => { connectStat.Text = "connected ClientA"; }));
}
//function
public void getFeedBack(string message){
string test = message;
}
感謝您的回答: )但我沒有發現任何區別。 – Damkulul
editted the answer – Kiong
好吧,我試過你的答案,但仍然沒有什麼變化:-(HubProxy.On(「getFeedBack」,msg => Dispatcher.CurrentDispatcher.InvokeAsync(()=> { MsgTxtBox.Text = msg; })); –
Damkulul