vb.net - BackgroundWorker's ProgressChanged not updating UI until end of work loop -
i coding wpf application grab email's off of imap account, , export them user-selected folder.
i use backgroundworker download emails. however, ui isn't being updated until loop over.
any tips appreciated.
class mainwindow public mailrepo mailrepository private bw_connect new backgroundworker private bw_save new backgroundworker public sub new() initializecomponent() bw_connect.workerreportsprogress = true bw_connect.workersupportscancellation = true addhandler bw_connect.dowork, addressof bw_connect_dowork bw_save.workerreportsprogress = true bw_save.workersupportscancellation = true addhandler bw_save.dowork, addressof bw_save_dowork addhandler bw_save.progresschanged, addressof bw_save_progresschanged end sub
private sub bw_save_dowork(byval sender object, byval e doworkeventargs) dim worker backgroundworker = ctype(sender, backgroundworker) if bw_connect.cancellationpending = true e.cancel = true else saveemails() end if end sub
private sub saveemails() dim allmails ienumerable(of message) 'get emails in mailbox try dim mailbox string dispatcher.invoke(directcast(sub() mailbox = comboboxemailfolders.selectedvalue end sub, action)) allmails = mailrepo.getallmails(mailbox) catch i4e imap4exception msgbox("error: folder not found" & vbcrlf & i4e.message) return end try dim msg message dim msgint integer = 1 'save each message each msg in allmails bw_save.reportprogress(100 / allmails.count * msgint, nothing) savemessage(msg) msgint += 1 next end sub
private sub bw_save_progresschanged(byval sender object, byval e progresschangedeventargs) dim percentdone string = e.progresspercentage.tostring() & "%" updatestatus("saving emails " & percentdone & " done.") progressbarstatus.value = e.progresspercentage end sub
Comments
Post a Comment