Domanda

Sto creando un'attività e quindi assegno un thread che attende il completamento dell'attività e quindi modificare l'interfaccia utente.

 string txt = txtHelloMessage.Text;
 HelloTask = Task<string>.Factory.StartNew(
            () =>
            {
                string msg = client.SayHello(txt);
                return msg;
            }
            );
 new Thread(
           () =>
            {
                while (true)// waiting for completion, I think that this is wrong
                {
                    if (HelloTask.IsCompleted)
                    {
                        this.Dispatcher.Invoke((Action)delegate() { txtHelloMessage.Text = HelloTask.Result; });
                        break;

                    }
                }

            }
            ).Start();

Questa è una buona pratica?

Nessuna soluzione corretta

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