c# - C # memory management and performance -
the criteria simple. developing winform application using c# 4.0 , have win form having grid view. on load event, retrieve data database , assign datasource gridview. have used backgroundworker object database retrieval. nice. gui responsive. records more 10 lac. fill datatable using background worker , assign datatable gridview. problem is, system gets slower. when minimize mdi form of application , try other things opening internet browser , stuff, pc gets slower. have core i3 2ith 2gb ram. grid having 10 lac records makes system slow. how manage memory in case? here code:
backgroundworker bworker; datatable dt;
public form1() { initializecomponent(); bworker = new backgroundworker(); bworker.dowork += new doworkeventhandler(m_oworker_dowork); bworker.progresschanged += new progresschangedeventhandler(m_oworker_progresschanged); bworker.runworkercompleted += new runworkercompletedeventhandler(m_oworker_runworkercompleted); bworker.workerreportsprogress = true; bworker.workersupportscancellation = true; } void m_oworker_runworkercompleted(object sender, runworkercompletedeventargs e) { datagridview1.datasource = dt; picturebox1.visible = false; //progressbar1.style = progressbarstyle.blocks; //label1.text = "data loaded successfully!"; this.hide(); this.show(); } void m_oworker_dowork(object sender, doworkeventargs e) { dt = getdatatable(); //bworker.reportprogress(100); } void m_oworker_progresschanged(object sender, progresschangedeventargs e) { //here play main ui thread //progressbar1.value = e.progresspercentage; } private void form1_load(object sender, eventargs e) { bworker.runworkerasync(); } private datatable getdatatable() { string constr = constring; sqlconnection con = new sqlconnection(constr); sqlcommand cmd = new sqlcommand("select *from testtable",con); sqldataadapter da = new sqldataadapter(cmd); dt = new datatable(); try { da.fill(dt); return dt; } catch (exception ex) { messagebox.show(ex.tostring()); return null; } }
please guide me how manage memory system should not slower. if dispose datatable after assigning grid, help?
i beginner. , want complete guidance memory management. application should fast. thanx
most problem datagridview creates row each row in result set. should read virtual display mode is, virtualmode property , how implement it.
Comments
Post a Comment