c# - Start a new Thread when one has finished: why am I not in a new Thread? -
this code:
private void taskgestionecartelle() { task.factory.startnew(() => generalistacartelle()) .continuewith(t => generalistacartellecompletata() , cancellationtoken.none , taskcontinuationoptions.none , taskscheduler.fromcurrentsynchronizationcontext()); } private void generalistacartelle() { // ... code } private void generalistacartellecompletata() { task.factory.startnew(() => copiacartelle()) .continuewith(t => copiacartellecompletato() , cancellationtoken.none , taskcontinuationoptions.none , taskscheduler.fromcurrentsynchronizationcontext()); } private void copiacartelle() { // long operation... }
in fact, when copiacartelle start, i'm not new thread, because take time, , ui totally freeze (while on generalistacartelle()
, take long time too, doesnt happens). because can write on controls in ui without using invokerequired
, methodinvoker
.
i miss points?
try changing task.factory.startnew(() => copiacartelle())
following:
task.factory.startnew(() => copiacartelle(), cancellationtoken.none, taskcreationoptions.none, taskscheduler.default))
you're going generalistacartellecompletata in continuation on ui thread, , scheduling task on ui thread seems - putting taskscheduler.default make run in own thread. (just tested confirm)
Comments
Post a Comment