signalR 客户端挂起等待()
signalR client hangs on wait()
SignalR 客户端挂起 wait();
这是我的代码
Proxy.Invoke<string>("IO_Table_Game_Status", getTableGameStateJsonReq).ContinueWith((responseJson) =>
{
string tablestatusResp = responseJson.Result;
}).Wait();
这里我需要获取tablestatusResp
中的Json值。但它显示的是空值。
var data=Proxy.Invoke<string>("IO_Table_Game_Status", getTableGameStateJsonReq).Result;
希望对您有所帮助。
由于(据我所知)SignalR 正在公开对真正的异步操作的访问(看起来它正在发送 HTTP 消息),我认为最好让您的应用程序利用这种异步性。它使维护和理解代码变得更加容易,并且在使用 Wait 方法及其兄弟方法时阻止调用死锁时,它使您免于陷入无数陷阱。
public async Task<TReturnType> YourCurrentMethod()
{
var tableStatusResp await Proxy.Invoke<string>("IO_Table_Game_Status", getTableGameStateJsonReq);
}
注意,方法签名是我编的,你只需要标记为async
,这样你就可以使用await
关键字了。
谢谢,我的问题终于得到了答案...我使用了 Dispatcher。这是代码
Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() =>
{
string tablestatusResp = Get_Info_Panel_Proxy.Invoke<string>("IO_Table_Game_Status", getTableGameStateJsonReq).Result;
}));
当我的集线器没有正确初始化时,我得到了这个。尝试创建一个原始的集线器,使用干净的构造函数和一个简单的方法来查看它是否一直挂起。
SignalR 客户端挂起 wait();
这是我的代码
Proxy.Invoke<string>("IO_Table_Game_Status", getTableGameStateJsonReq).ContinueWith((responseJson) =>
{
string tablestatusResp = responseJson.Result;
}).Wait();
这里我需要获取tablestatusResp
中的Json值。但它显示的是空值。
var data=Proxy.Invoke<string>("IO_Table_Game_Status", getTableGameStateJsonReq).Result;
希望对您有所帮助。
由于(据我所知)SignalR 正在公开对真正的异步操作的访问(看起来它正在发送 HTTP 消息),我认为最好让您的应用程序利用这种异步性。它使维护和理解代码变得更加容易,并且在使用 Wait 方法及其兄弟方法时阻止调用死锁时,它使您免于陷入无数陷阱。
public async Task<TReturnType> YourCurrentMethod()
{
var tableStatusResp await Proxy.Invoke<string>("IO_Table_Game_Status", getTableGameStateJsonReq);
}
注意,方法签名是我编的,你只需要标记为async
,这样你就可以使用await
关键字了。
谢谢,我的问题终于得到了答案...我使用了 Dispatcher。这是代码
Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() =>
{
string tablestatusResp = Get_Info_Panel_Proxy.Invoke<string>("IO_Table_Game_Status", getTableGameStateJsonReq).Result;
}));
当我的集线器没有正确初始化时,我得到了这个。尝试创建一个原始的集线器,使用干净的构造函数和一个简单的方法来查看它是否一直挂起。