クライアントがサーバーにメッセージを送信したいときに表示するWPF-Applicationに「読み込みウィンドウ」を実装しようとしていて、受け取った。非同期メソッドを使用すると、これは大きな問題ではありませんが、の後にウィンドウがと表示され、応答が瞬時に(期待通りに)閉じられます。C#すべてのコードが実行された後に非同期ウィンドウが表示される
はここにいくつかのコードが実行の
public async Task<CommunicationMessage> SendAndReadMessageSync(string message, bool showLoadingScreen = true) {
// Show loading screen if needed
if (showLoadingScreen == true) {
await Globals.MessageController.ShowLoadingScreen(); // This method is the second one
}
// Send a message to the server
SendMessageSync(message);
// Receive the response from the server
CommunicationMessage response = ReadMessageSync();
// Close loading screen
if (showLoadingScreen == true) {
await Globals.MessageController.CloseLoadingScreen();
}
// return the 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 the loading screen
LoadingScreen ls = new LoadingScreen(title, message) {
IsModal = true
};
// Store the screen inside list
loadingScreens.Add(ls);
// Show the screen
await this.ShowChildWindowAsync(ls, ChildWindowManager.OverlayFillBehavior.FullWindow);
}));
}
マイthinkingsは、ロード画面は独立して10秒間続く可能性がSendMessageSync()方法 - の表示されますことをしているスニペットです。クライアントが応答を受け取ると、読み込み中の画面が閉じます。
何か間違っているのですか、何か忘れましたか?もっとコードが必要な場合はお知らせください
ありがとうございます!
これは答えでした!大いに感謝する! –