VB.net BackgroundWorker Pause/Resume -
i want create 2 buttons pause , resume backgroundworker don't know start code, have started learning vb.net , wanted learn pause , resume function of backgroundworker.
here existing backgroundworker code wish pause , resume
public resetevent new manualresetevent(false) dim boo nullable(of boolean) = true private sub button3_click(sender object, e eventargs) handles button3.click try if backgroundworker2.isbusy <> true backgroundworker2.runworkerasync() resetevent.set() end if catch ex exception end try end sub private sub backgroundworker2_dowork(sender system.object, e system.componentmodel.doworkeventargs) handles backgroundworker2.dowork dim worker2 system.componentmodel.backgroundworker = ctype(sender, system.componentmodel.backgroundworker) try dim stream new system.io.filestream("sample.txt", io.filemode.open) dim sreader new system.io.streamreader(stream) dim index integer = 0 while sreader.peek >= 0 resetevent.waitone() thread.sleep(500) elist.add(sreader.readline) delay(1) loop earray = elist.toarray thread.sleep(1000) stream.close() sreader.close() catch ex exception messagebox.show(ex.message) end try end sub private sub backgroundworker2_progresschanged(sender system.object, e system.componentmodel.progresschangedeventargs) handles backgroundworker2.progresschanged try catch ex exception end try end sub private sub backgroundworker2_completed(sender system.object, e system.componentmodel.runworkercompletedeventargs) handles backgroundworker2.runworkercompleted try resetevent.reset() catch ex exception end try end sub private sub pause_click(sender object, e eventargs) handles pause.click pause.enabled = false resme.enabled = true if backgroundworker1.isbusy boo = false resetevent.reset() end if end sub private sub resme_click(sender object, e eventargs) handles resme.click resme.enabled = false pause.enabled = true if backgroundworker1.isbusy boo = true resetevent.set() end if
this code working tips
please take @
pause/resume loop in background worker
and
how pause , resume backgroundworker?
also
how implement pause & resume functionality backgroundworker c#
use converter code need converted.. should have answer you.
Comments
Post a Comment