Domanda

Ho un Windows SVC che funziona in modo asincrono (ho modificato i metodi e i loro parametri per renderli asincroni), un po 'come: http://msdn.microsoft.com/en-us/library/ms731177.aspx

Tuttavia, chiamo l'attività che voglio eseguire in modo asincrono (la chiamata al servizio/server), quindi aggiornare l'interfaccia utente (usando reportProgress () sul backgroundworker - tutto ciò sta accadendo nel metodo Dowork () di un lavoro in background ). Tuttavia, chiamo il metodo ENDXXX per ottenere i risultati, ma il problema è che il mio codice non dovrebbe apparire?

while (!asyncresult.IsCompleted) { // Do all UI updating etc here... }

// Call endXXX here.

Tuttavia, questo approccio blocca l'interfaccia utente. Al momento, il mio codice è così (e non blocca l'interfaccia utente):

 IAsyncResult res = null;

                try
                {

                    res = serviceX.BeginXXX(ResultCallBack, "");
                }
                catch (FaultException<ManagementException> managementEx)
                {
                    Logger.Error(managementEx.Detail.ToString());
                    MessageBox.Show("Could not add printer. See log.");
                }



                    InstallBackgoundWorker.ReportProgress(90);
                    InstallBackgoundWorker.ReportProgress(91);
                    InstallBackgoundWorker.ReportProgress(93);

                    InstallBackgoundWorker.ReportProgress(94);
                    InstallBackgoundWorker.ReportProgress(95);
                    InstallBackgoundWorker.ReportProgress(96);
                    InstallBackgoundWorker.ReportProgress(97);



                    if (res.IsCompleted)
                    {
                        ResultCallBack(res);
                    }
                    InstallBackgoundWorker.ReportProgress(100);

È corretto? Mi sembra sbagliato.

Nessuna soluzione corretta

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top