클라이언트가 서버에 메시지를 보내려고 할 때 표시해야하는 WPF-Application에 "Loading Window"를 구현하려고 시도하고 응답 후 닫아야합니다. 받았어요. 비동기 메서드를 사용하면 큰 문제는 아니지만 이후에 창에 이 표시되어 예상대로 응답이 즉시 닫힙니다.모든 코드가 실행 된 후 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() -Method의 표시 것입니다 니펫입니다. 클라이언트가 응답을 받으면 로딩 화면이 닫힙니다.
내가 뭔가 잘못하고있는 걸까요, 아니면 뭔가 잊었습니까? 더 많은 코드가 필요하면 알려주세요.
고마워요!
답변입니다. 정말 고마워! –