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
Post a Comment