c# - When reporting progress and updating ui listView control the whole program is stuck i can't click on other buttons why? -
i mean in backgroundworker can click on other controls use other controls while backgroundworker working. once i'm trying update ui listview control it's updating else freezing/stuck can't click , use other controls until backgroundworker finish work.
int countuploadmsg = 0; private void backgroundworker2_dowork(object sender, doworkeventargs e) { mimekit.headerlist loaded = new mimekit.headerlist(); list<string> test = new list<string>(); int counter = 0; mimekitallloadedmessages = new list<mimekit.mimemessage>(); mimekit.mimemessage loadedmessage = null; (int = 0; < files.length; i++) { string uid = seenuids[0]; loadedmessage = mimekit.mimemessage.load(files[i].fullname); downloaded.add(seenuids[i]); counter += 1; int nprogress = counter * 100 / files.length; backgroundworker2.reportprogress(nprogress, loadedmessage); } }
the progresschanged event
private void backgroundworker2_progresschanged(object sender, progresschangedeventargs e) { pbt1.value = e.progresspercentage; pbt1.text = e.progresspercentage.tostring() + "%"; pbt1.invalidate(); label9.text = countuploadmsg.tostring(); label9.visible = true; mimekit.mimemessage msg = e.userstate mimekit.mimemessage; listviewcostumcontrol.lvnf.items.add(msg.tostring()); }
what did try far ? added sleep 1 ms , changed 50ms in dowork event after reportprogress line. w hen setting sleep 50ms working fine slow.
i tried update mimekitallloadedmessages list in dowork event adding loadedmessage , reporting mimekitallloadedmessages list e.userstate or updating listview in progresschanged event list.
tried add sleep of 1ms in progresschanged.
the far sleep 50ms in dowork event process getting slow.
i tried small amount of files changed in loop in dowork files.length 1000 500 , same problem.
even setting sleep 50ms not times working smooth.
mimekit email lib if it's matter @ all:
the problem doing more work in progresschanged
handler in background thread. worker thread generating progresschanged
events faster main thread can handle them.
you can use stopwatch
time method block in dowork
for-loop , in progresschanged
handler.
you'll have reconsider approach here - change of strategy needed.