c# - Using async/await: await returns too early -
i have simly windows forms app button , progressbar on it.
then have code:
private async void buttonstart_click(object sender, eventargs e) { progressbar.minimum = 0; progressbar.maximum = 5; progressbar.step = 1; progressbar.value = 0; await convertfiles(); messagebox.show("ok"); } private async task convertfiles() { await task.run(() => { (int = 1; <= 5; i++) { system.threading.thread.sleep(1000); invoke(new action(() => progressbar.performstep())); } }); }
the await convertfiles();
returns early, ok messagebox appears @ 80% progress.
what doing wrong?
the problem experiencing not related async/await
, use correctly. await
not returning early, progress bar updates late. in other words, progress bar control specific problem described in several threads - disabling .net progressbar animation when changing value?, disable winforms progressbar animation, the runworkercompleted triggered before progressbar reaches 100% etc. can use 1 of workarounds provided in threads.
Comments
Post a Comment