c# - How do I invoke method after a task is completed? -
hello i'm trying alert user when images have been deep zoomed , zipped. each image asynchronously deep zoomed , zipped , after images have been deep zoomed , zipped wish alert user pop up.
var z = task.factory.startnew( () => { cr.create(current_file_name, output); file.copy(path.getdirectoryname(assembly.getexecutingassembly().location) + "\\htmlviewer.html", outputpath + "\\htmlviewer.html", true); zipfile.createfromdirectory(outputpath, directory.getparent(outputpath) + "\\" + path.getfilenamewithoutextension(current_file_name) + ".zip"); }); var tasks = new[] { z }; var continued = task.whenall(tasks).continuewith((antecedent) => { _window.maindispatcher.begininvoke(new action( () => { _popup.popuptext = "deepzoom completed"; _popup.beginpopuptimer(); })); }, taskcontinuationoptions.onlyonrantocompletion);
i used followed solution example : https://stackoverflow.com/questions/12248832/how-to-check-that-all-tasks-have-been-properly-completed#= can't seem working. clarify; code within foreach iterates through set of images. when images have been zipped, want _popup.beginpopuptimer
method invoked.
try use async await
private async task domywork() { var z = task.factory.startnew( () => { cr.create(current_file_name, output); file.copy(path.getdirectoryname(assembly.getexecutingassembly().location) + "\\htmlviewer.html", outputpath + "\\htmlviewer.html", true); zipfile.createfromdirectory(outputpath, directory.getparent(outputpath) + "\\" + path.getfilenamewithoutextension(current_file_name) + ".zip"); }); var tasks = new[] { z }; await task.whenall(tasks); _window.maindispatcher.begininvoke(() => { _popup.popuptext = "deepzoom completed"; _popup.beginpopuptimer(); }); }
when have 1 task not have use task.whenall
. can use use:
await task.factory.startnew( () => { cr.create(current_file_name, output); file.copy(path.getdirectoryname(assembly.getexecutingassembly().location) + "\\htmlviewer.html", outputpath + "\\htmlviewer.html", true); zipfile.createfromdirectory(outputpath, directory.getparent(outputpath) + "\\" + path.getfilenamewithoutextension(current_file_name) + ".zip"); }); _window.maindispatcher.begininvoke(() => { _popup.popuptext = "deepzoom completed"; _popup.beginpopuptimer(); });
Comments
Post a Comment