c# - DispatcherTimer and Show Modal Window -
let's see if can explain me behaviour , maybe how can solve this. have wpf
app, , in viewmodel have dispatchertimer
. in viewmodel have command show modal window, this:
private void showwindowcommandexecuted() { wnnewwindow window = new wnnewwindow(); window.showdialog(); }
when call command button, new window shown , dispatchertimer
keeps running in background. far good. problem when try show window dispatchertimer
this:
dispatchertimer timerinstrucciones; timerinstrucciones = new dispatchertimer(); timerinstrucciones.interval = timespan.frommilliseconds(1000); timerinstrucciones.tick += (s, e) => { wnnewwindow window = new wnnewwindow(); window.showdialog(); }; timerinstrucciones.start();
in case, new window shown, long visible, dispatchertimer
stops "ticking". understand dispatchertimer
runs in ui thread, why behaves in different way in case?
generally, showdialog
modal dialog block calling thread, , show dialog. block interaction parent/owning window too.
as long close modal dialog, ui-thread blocked. because dispatchertimer
, belongs window's dispatcher , runs in same thread. if thread blocked, dispatchertimer
stops running.
update based on comments:
i haven't went through documentation on this, basic difference dispatchertimer
run synchronously
, not in asynchronous
way.
won't block dispatcher:
timerinstrucciones.tick += (s, e) => { this.dispatcher.begininvoke(new action(() => { wnnewwindow mn = new wnnewwindow(); mn.showdialog(); })); };
will block dispatcher:
timerinstrucciones.tick += (s, e) => { this.dispatcher.invoke(new action(() => { wnnewwindow mn = new wnnewwindow(); mn.showdialog(); })); };
since, dispatcher
invoke
event
on every n seconds, event
cannot called anymore, if thread got blocked operation inside calling event
.
Comments
Post a Comment