c# - MethodInvoker lost? -
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() { if (txtlog.invokerequired) { txtlog.begininvoke(new methodinvoker(delegate { txtlog.appendtext("copio cartelle in corso..." + environment.newline); })); } }
it start thread. when finish, start thread (from continue with) , try write somethings in control on ui. in fact nothing written on txtlog
. wrong?
i try write somethings in control on ui. in fact nothing written on txtlog. wrong?
because @ time, invoke not required. can modify if statement , add else
part same.
private void copiacartelle() { if (txtlog.invokerequired) { txtlog.begininvoke(new methodinvoker(delegate { txtlog.appendtext("copio cartelle in corso..." + environment.newline); })); } else // part when invoke not required. { txtlog.appendtext("copio cartelle in corso..." + environment.newline); } }
you can refactor text append path method , call method if-else
Comments
Post a Comment