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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -