I call a WCF and the Completed event of method is call after the awaiting method.
public void my_method()
{
Task task = Task.Run(async () => await DoWorkAsync());
task.Wait();
}
public async Task DoWorkAsync()
{
await Task.Run(() =>
{
wcf1.ServiceAnnonces s = new wcf1.ServiceAnnonces();
s.DoWorkCompleted += S_DoWorkCompleted;
s.DoWorkAsync();
});
}
private string retour;
public string Retour { get => retour; set => retour = value; }
private void S_DoWorkCompleted(object sender, wcf1.DoWorkCompletedEventArgs e)
{
Retour = e.Result;
}
I call method with this code :
Droid.Resources.ISvAnnoncesSoap s = new Droid.Resources.ISvAnnoncesSoap();
s.ma_methode();
LbResulat.Text = s.Retour;
My service :
[ServiceContract]
public interface IServiceAnnonces
{
[OperationContract]
string DoWork();
}
public class ServiceAnnonces : IServiceAnnonces
{
public string DoWork()
{
return "coucou";
}
}
}
But le Completed event is throw after LbResulat.Text = s.Retour;
Thank for your help.
EDIT :
I delete some line code. My code now :
public void ma_methode()
{
wcf1.ServiceAnnonces s = new wcf1.ServiceAnnonces();
s.DoWorkCompleted += S_DoWorkCompleted;
s.DoWorkAsync();
}
private string retour;
public string Retour { get => retour; set => retour = value; }
private void S_DoWorkCompleted(object sender, wcf1.DoWorkCompletedEventArgs e)
{
Retour = e.Result;
}
And to call directly :
Droid.Resources.ISvAnnoncesSoap s = new Droid.Resources.ISvAnnoncesSoap();
s.ma_methode();
LbResulat.Text = s.Retour;
But same, But the Completed event is throw after LbResulat.Text = s.Retour; So my Retour is null.