I want to run a long running process in a windows service asynchronously - and poll the process every 3 seconds and report back using SignalR. The code below will ( theoretically ) do this in an event based way , but I don't want to be firing of the progress with every single change.
Can someone please provide a simple example of how to implement this specifically to start the process and poll / report progress. Please bear in mind I have been out of full time development for a few years!
public async Task<string> StartTask(int delay)
{
var tokenSource = new CancellationTokenSource();
var progress = new Progress<Tuple<Int32, Int32>>();
progress.ProgressChanged += (s, e ) =>
{
r2hProcessesProxy.Invoke("DownloadNotify", string.Format("Major={0} - Minor={1}", e.Item1 , e.Item2 ));
};
var task = DownloadTask.DoDownload(delay, tokenSource.Token, new Progress<Tuple<Int32,Int32>>(p => new Tuple<Int32, Int32>(0,0)));
await task;
return "Task result";
}