c# - Freezing UI and odd thread behavior (WPF) -


i building application wpf , c# , have run odd problem. there multiple threads in application, many of created through system.timer timers. there particular action can take cause ui of application freeze; ui freeze permanently when happens. oddest thing though if check number of available threads threadpool.getavialbalethreads, number of available threads continuously diminish if don't stop application. of threads in application created either via timer or task.startnew method.

there several parts of code spin new threads, try show of them here in abbreviated way.

datamanager.cs

// 2 system.timers.timer(s) handle generating data values on 3 second , 1.5 second intervals. _averagetimer = new system.timers.timer(1000 * 3); _averagetimer.elapsed += generatenewaveragepoint; _averagetimer.enabled = false;  _flowgentimer = new system.timers.timer(1000 * 1.5); _flowgentimer.elapsed += generatenewflowset; _flowgentimer.enabled = false;  // have primary work loop in class created via task // function runs continuously task.run(() => processdata());  // send off task file i/o every 3 seconds task.run(() => {     lock (_shareddata.filelock)     {             _continuousfilemanager.writedatasubset(tmpdata);     } });  // finally, have similar file i/o function 1 above, // called in timer fires every 3 seconds task.run(() => {     lock (_shareddata.filelock)     {             _averagefilemanager.writedatasubset(tmpdata);     } }); 

so class appears utilize max of 6 threads.


in class have 3 calls dispatcher.invoke

advancedpanel.cs

// realtimedataflowitems observablecollection application.current.dispatcher.invoke(delegate {       realtimedataflowitems.insert(0, avgflow); });  // realtimedatahritems observablecollection application.current.dispatcher.invoke(delegate {       realtimedatahritems.insert(0, avgflow); });  // realtimedatatimeitems observablecollection application.current.dispatcher.invoke(delegate {       realtimedatatimeitems.insert(0, avgflow); }); 


in class have 1 call dispatcher.invoke datainfo.cs

application.current.dispatcher.invoke(delegate {     indicatorpoints = new pointcollection(new[] { /* removed brevity */}); } 


in class there 2 system.timers.timer(s) execute @ intervals of 15 ms , 2 seconds.

plotdata.cs

_plottimer = new system.timers.timer(15); _plottimer.elapsed += processloop; _plottimer.enabled = false;  _boundstimer = new system.timers.timer(1000 * 2); _boundstimer.enabled = false; _boundstimer.elapsed += checkyaxisbounds; 

also, class utilizes oxyplot plotting library in order present realtime data in ui. oxyplot has modify ui, performing actions on ui thread.



final note, use caliburn.micro in application , make use of eventaggregator heavily. each time wish publish message new task started startnew method. of classes in application make use of eventaggregator in capacity, there several threads become utilized these actions.

i hope information helpful, please let me know if there more should provide. hoping 1 of provide me insight on might happening, , how might able go debugging , solving ui freezing issue. thank help!


Comments

Popular posts from this blog

PySide and Qt Properties: Connecting signals from Python to QML -

c# - DevExpress.Wpf.Grid.InfiniteGridSizeException was unhandled -

scala - 'wrong top statement declaration' when using slick in IntelliJ -