vb.net - Jump out of code if a button is pressed -


is there way have 'listener' of sorts listen button click in middle of code? there scenarios won't have wait code complete before can exit functions cannot seem find way see if button clicked other throwing ton of if checks throughout function calls doesn't seem efficient me.

this code runs on thread, different main application

private function longrunningfunction()     din canceled boolean  = false ' make sure canceled while in loop     ' long loop     integer = 0 100000         if _cancelexecution             canceled = true             exit         end if         ' code runs here         .........     next      if canceled           ' wrap thread, clean stuff, etc      end if     ....................... end function 

on main thread, when button clicked _cancelexecution set true

the backgroundworker has mechanism built-in already


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -