Salut à tous
Voila, j'ai beau chercher et tester mais ça ne passe pas !
J'essaye d’imbriquer un WebClient.DownloadStringCompleted au sein d'un dispatcher pour bloquer le thread principal en attente de ma réponse.
J'ai essayé de reprendre ce principe
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 public void getData() { string uri = "http://" + ip + "/Isibudget/login/login.php?login=" + log + "&mdp=" + mdp; client.DownloadStringCompleted += ClientConnec; client.DownloadStringAsync(new Uri(uri)); } public void ClientConnec(object sender, DownloadStringCompletedEventArgs e) { userFromPhp = e.Result }
mais le thread principal a filé sans attendre !
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 ManualResetEvent completionEvent = new ManualResetEvent(false); WebClient webClient = new WebClient(); webClient.DownloadStringCompleted +=delegate(object sender, DownloadStringCompletedEventArgs e) { completionEvent.Set(); }; webClient.DownloadStringAsync(new Uri(uri)); completionEvent.WaitOne();
Quelqu'un aurait une idée pour faire marcher cette solution ou aurait une toute autre solution ?
Merci, bonne soirée !
Partager