I have a Hub class that has a long running method, I need to display a progress bar while I work.
I read this article and I think that you can use the IProgress interface in asynchronous methods to send a long working state.
I am writing a method like this:
public async Task<string> GetServerTime(IProgress<int> prog)
{
await Task.Run(() => {
for (int i = 0; i < 10; i++)
{
prog.Report(i * 10);
System.Threading.Thread.Sleep(200);
}
});
return DateTime.Now.ToString();
}
And I am trying to call the method as follows:
var appHub = $.connection.appHub;
$.connection.hub.start();
appHub.server.getServerTime()
.done(function (time) {
alert(time);
});
But I do not know how I can get progress reports.
source
share