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
Post a Comment