c# - How to stop backgroundworker on page refresh or page close in mvc5? -


i have mvc5 application has excel upload huge data excel , save database using ef. using backgroundworker upload , progress. when user clicks other link or page refresh in middle of fileupload , if upload someother file, previous progress showing in middle of new upload. mean previous process not killing. how solve issue?

bwprocess = new backgroundworker{ workerreportsprogress = true, workersupportscancellation = true }; bwprocess.dowork += new doworkeventhandler(bwprocess_dowork); bwprocess.progresschanged += new progresschangedeventhandler(bwprocess_progresschanged); bwprocess.runworkercompleted += new runworkercompletedeventhandler(bwprocess_runworkercompleted)‌​; task.run(() => bwprocess.runworkerasync("asyncworker2")); 

better use task option taskcreationoptions.longrunning , don't careless static instances or "global" instances in process.

look at:

var task3 = new task(() => mylongrunningmethod(),                     taskcreationoptions.longrunning); task3.start(); 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -