MODIFICATO: su Windows Phone Sto chiamando HttpWebRequest.BeginGetResponse
su un thread separato che è stato avviato . Quindi chiamo MessageBox.Show(). Il problema è che il callback non viene chiamato fino a quando non congedo il MessageBox.HttpWebRequest callback è bloccato dall'interfaccia utente
void GetResponseCallback(IAsyncResult asynchronousResult) {
//Not getting called until I dismiss MessageBox
}
void getWeb() {
Thread.Sleep(1000);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(url));
request.Method = "GET";
request.BeginGetResponse(new AsyncCallback(GetResponseCallback), request);
}
new Thread(getWeb).Start(); //Start a new thread
MessageBox.Show();
Il MessageBox deve bloccare la richiamata sul thread in background?
piccola domanda: perché si fa a creare thread separato 'new Thread (GetWeb)' per il metodo 'GetWeb()' che è già asincrono da solo (il metodo 'request.BeginGetResponse (...)' fa il suo lavoro in background)? –
L'idea è che avrò un ciclo sul thread in background che invia continuamente richieste web con una pausa di un paio di minuti tra ogni richiesta. Risolverà il mio problema se chiamo BeginGetResponse nel thread dell'interfaccia utente? – user1740959
Potrebbe avere a che fare con ciò che viene * dopo * anche la chiamata, il metodo non viene mai chiamato, o si colpisce il metodo di callback e non viene chiamato il codice che effettua il marshalling della chiamata all'interfaccia utente? Sembra che tu abbia una sorta di stallo in corso. – casperOne