c# - Auto refresh using Task -
I have a chart component that is working very well and now I need to implement auto refresh system. Therefore, the chart will be constantly updated in the timeframe set by the user in the run time (30 sage, 1 minute, ...). How do I use the work to get this, but I saw that the job does not have a timer.
So, have you done something similar in the past? What is the best way to think? Threads? BackGroundWorker?
My project is .NET 4.0 and I can not modify it
You Task.Delay (which is internally a Based system.Threading.Timer ), you need to write, which creates a completed task after a certain time:
async Task Auto-refresh (Timespain interval, cancellation token token) {While (! Token.IC cancellation request) {Refresh (); Awaiting work Divine (interval); }} You can call it at startup with a specific interval and should stop it when prompted for a cancellation token . This will do an action that you can do waiting at the end to make sure that you do not have any unrelated exceptions:
// start var interval = GetIntervalFromUser (); _cts = new cancellation (); _autoRefreshTask = Auto Refresh (Interval, CTS.Token); // And Detectives cancel (); Try {Wait _autoRefreshTask; } Hold (Exception e) {// Handle Exception} In the async-await in Net 4.0 in
Comments
Post a Comment