c# - TPL does not start task -
i following:
private void ontimedevent(object sender, elapsedeventargs e) { tokensource.cancel(); receivedatatimer.stop(); console.writeline("timer done"); } private void eventdatareceived(message msg) { dataque.enqueue(msg.data); var context = new dispatchersynchronizationcontext(application.current.dispatcher); if(receivedatatimer.enabled==false) { console.writeline("start task"); tokensource = new cancellationtokensource(); task.factory.startnew(() => work(tokensource.token, maxpoints), tokensource.token); task.factory.startnew(() => update(context, tokensource.token), tokensource.token); receivedatatimer.start(); } else { receivedatatimer.interval=3000; } }
basically, there timer sets token cancel 2 tasks. after while timer restarted , 2 tasks should started again. don't.
can tell me why? both start first time running application.
i added more code now. when data received serial port, eventdatareceived called. debugged , timer should.
data received -> start task -> start timer -> (if 3s no data received) stop tasks -> (if data received) restart task , timer.
but tasks not start again.
Comments
Post a Comment