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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -