c# - how to close main thread from sub thread -


i working on vsto. had long time consuming process need implement stop button stop process. create ui form stop button , show ui form in sub thread when main process called. trying stop main process ui stop button tried closed process , document self need stop process have tried these closing process not work

enviorment.exit(1); process.kill(); process.close(); close(); 

i not sure why calling thread "process", question sub thread, i'll answer threads.

if want end thread, make regulary test public bool, defined in dialogbox class "public volatile bool stoprequested = false;" if bool set true, use "return" keyword stop thread.

to abort thread dialog box, enter btn_click event: "this.stoprequested = true;"

the thread realise use wants stop, , jump line "return". thread closed! \o/


Comments