Signalr 导航到其他页面并返回时,信号器进度条未恢复
我在web表单应用程序(不是MVC,MVVM)中使用signalR在显示进度百分比的页面上显示进度条,我的问题是当我导航到其他页面并返回到上一页时,进度条会重新启动。我希望它从我离开的地方恢复。下面是我的信号集线器代码-Signalr 导航到其他页面并返回时,信号器进度条未恢复,signalr,progress-bar,Signalr,Progress Bar,我在web表单应用程序(不是MVC,MVVM)中使用signalR在显示进度百分比的页面上显示进度条,我的问题是当我导航到其他页面并返回到上一页时,进度条会重新启动。我希望它从我离开的地方恢复。下面是我的信号集线器代码- public void CallLongOperation() { for (int x = 0; x <= count; x++) { // delay the process for see things
public void CallLongOperation()
{
for (int x = 0; x <= count; x++)
{
// delay the process for see things clearly
Thread.Sleep(1000);
if (x == 20)
msg = "Loading Application Settings...";
else if (x == 40)
msg = "Applying Application Settings...";
else if (x == 60)
msg = "Loading User Settings...";
else if (x == 80)
msg = "Applying User Settings...";
else if (x == 100)
msg = "Process Completed!...";
// call client-side SendMethod method
Clients.Caller.sendMessage(string.Format
(msg + " {0}% of {1}%", x, count), x);
}
}
public void calllong操作()
{
对于(intx=0;x,我将尽可能简单地解释这个问题
此代码:
// establish the connection to the server and start server-side operation
$.connection.hub.start().done(function () {
// call the method CallLongOperation defined in the Hub
progressNotifier.server.callLongOperation();
});
每次重新加载页面并重新建立与集线器的连接时,都在服务器上执行您的方法。您需要:
将你的网页设计成SPA(单页应用程序),这样它们就不需要重新加载
将每个用户的值存储在静态ConcurrentDictionary
中,以便服务器能够“记住”每个用户的进度条状态
在我看来,这是您仅有的两个没有重大重新架构的选项。我的回答是否有用?