c# - Where does Dispatcher get control from? -


in user-control, have thread besides main thread process data, show result in text box this

private delegate void settextcallback(string text); private void settext(string text) {     if (!dispatcher.checkaccess())     {         dispatcher.invoke(new settextcallback(settext), text);         return;     }     txtresult.text = text; }  private void processthread() {     string result = "";     // process ...     settext(result); } 

on first application run, user-control worked perfectly. if close , open again, it's not working. debug settext function, txtresult.text show value has been assigned it's empty on ui. tried other controls enabling button result same: in debug, controls had held new value not on ui. got feeling thread got controls closed user-control.

can tell me what's wrong ? in advance , sorry bad english.

update

my thread initilization:

private timer _timer; public myusercontrol() {     initializecomponent();     _timer = new timer(processthread); } 

where call thread

private void _onsomecustomevent(object sender) {     if (sender != null)     {         _timer.change(timespan.fromseconds(5), timespan.fromminutes(10));     } } 

move txtresult.text = text; inside dispatcher invoke

dispatcher should used access ui controls background thread

this should work


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -