wpf - C# Async window showing after all code was running -
i trying implement "loading window" wpf-application should shown when client wants send message server , should closed after responce received. use async methods, should not big problem, somehow window shows after response received , closes instantly (as expected).
here code snippets
public async task<communicationmessage> sendandreadmessagesync(string message, bool showloadingscreen = true) { // show loading screen if needed if (showloadingscreen == true) { await globals.messagecontroller.showloadingscreen(); // method second 1 } // send message server sendmessagesync(message); // receive response server communicationmessage response = readmessagesync(); // close loading screen if (showloadingscreen == true) { await globals.messagecontroller.closeloadingscreen(); } // return response return response; } public async task showloadingscreen(string title = "lade daten", string message = "einen moment geduld bitte") { await dispatcher.begininvoke(new action(async delegate { // create loading screen loadingscreen ls = new loadingscreen(title, message) { ismodal = true }; // store screen inside list loadingscreens.add(ls); // show screen await this.showchildwindowasync(ls, childwindowmanager.overlayfillbehavior.fullwindow); })); }
my thinkings of executions loading screen show independently of sendmessagesync()-method last 10 seconds. after client gets response loading screen closed.
am doing wrong or did forget something? if need more code please let me know
thanks lot!
i suggest encapsulate sending of message in task. right run on ui thread. looks ui thread bussy , cannot show waiting window.
Comments
Post a Comment