c# - Thread that talk with UI? -


i have code:

private void buttonstart_click(object sender, eventargs e) {     task.factory.startnew(() => generalistacartelle())         .continuewith(t => generalistacartellecompletata()         , cancellationtoken.none         , taskcontinuationoptions.none         , taskscheduler.fromcurrentsynchronizationcontext()); }  private void generalistacartelle() {     try     {         ... operation ....     }     catch (exception err)     {         txterrors.appendtext(err.message);     } }  generalistacartellecompletata() {     ... process finished... } 

and txterrors in "main" thread (the ui). when catch error, asynch thread cannot write ui control, , invalid cross-thread exception.

can dialogate ui inside thread?

if targetting winform application then:

try     {         ... operation ....     } catch (exception err)     {        if (txterrors.invokerequired)         {             txterrors.begininvoke(new methodinvoker(                 delegate { txterrors.appendtext(err.message); })                 );         }     } 

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 -