c# - Slow updating of UI with WPF and Oxyplot -


what i'm trying accomplish here want grab data csv file copy 1 folder , put temp folder (so don't tamper original).

then want read in data csv file , plot last 2000 data points on graph using scatter series in oxyplot (i want check new data every 200 ms used dispatcher timer). issue i'm having first few updates plot great , plots how want to... however, after maybe 12 updates graph not update, or updates extremely causing ui become unresponsive.

below code part of project...

    public mainwindow()     {         viewmodel = new view_model.mainwindowmodel();         datacontext = viewmodel;          compositiontarget.rendering += compositiontargetrendering;          initializecomponent();     }      private void autoupdategraph()  //begins when check box ischecked = true     {         sw.start();         system.windows.threading.dispatchertimer dispatchertimer = new system.windows.threading.dispatchertimer();         dispatchertimer.tick += new eventhandler(dispatchertimer_tick);         dispatchertimer.interval = new timespan(0, 0, 0, 0, 200);         dispatchertimer.start();     }      private void dispatchertimer_tick(object sender, eventargs e)     {         sleevedata sd = new sleevedata();          //class deal data         filemanagement fm = new filemanagement();  //class manage files          string date = fm.getdate();                //get current date use in finding                                                     //most recent csv file          _newpath = fm.initialfilesetup(date);      //create new path temp file          fm.rewritefile(_newpath);                  //write temp file temp path          if (fm.isfilelocked(_newpath) == false)   //checking if file being written         {             ienumerable<sleevedata> newsd = sd.getmostrecentcsvdata(_newpath); //getting latest data temp file              viewmodel.loaddata(newsd); //updating data on graph         }     } 

and here loaddata method in mainwindowmodel...

    public void loaddata(ienumerable<sleevedata> newdata)     {         var scatterseries1 = new oxyplot.series.scatterseries         {             markersize = 3,             title = string.format("sleeve data"),         };          int j = 0;          var zerobuffer = new list<float>(new float[2000]);         var fdiadatabuffer = zerobuffer.concat((newdata.select(x => x.fdiameter).tolist())).tolist();         var idiadatabuffer = zerobuffer.concat((newdata.select(x => x.idiamax).tolist())).tolist();          (int = fdiadatabuffer.count - 2000; <= fdiadatabuffer.count - 1; i++)         {             scatterseries1.points.add(new scatterpoint(j, fdiadatabuffer[i]));             j++;         }          plotmodel.series.clear();         plotmodel.series.add(scatterseries1);     } 

i'm doing funky stuff latest 2000 points , add them graph.

maybe need consider background worker?

i might going wrong, , if love know in direction should go! i'm new coding projects large , ones must run real time. please go easy on me :) , in advance.

some suggestions:

use stopwatch in loaddata() method see how long it's taking. don't how data in these files, of linq stuff looks benefit optimisation - there lots of tolists() , repeated selects on same set of data. this:

var sw = new stopwatch(); sw.start();  ... stuff  debug.writeline(sw.elapsedmilliseconds); 

you try stopwatch in timer delegate, see how long entire "cycle" takes, in case it's taking longer 200ms. don't know if dispatchertimer can suffer re-entrancy, timer fires again before previous "tick" has completed, degrade performance.

the problem might lie charting component. i've had similar issues when working large wpf datagrids - creating data isn't particularly taxing - it's rendering takes time. @ end of loaddata() see clear down chart series repopulate it. i've found doing data source large datagrid creates "double-whammy", renders after clear(), renders again after repopulating data. i'm not familiar oxyplot see if can find alternative approach, if feasible, e.g. re-using series rather clearing down , adding again.

if poor performance turn out oxyplot, purchasing different chart component option? can thoroughly recommend scichart, we've been using various high performance/high volume scientific charting applications (i'm not affiliated them btw!).


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -