Bonjour
Je me bat un peu pour intégrer le concept de async await et c'est pas encore tres clair
Je pensais que le await permettait d'emuler une execution synchrone mais en test, ca semble tout l'inverse

Pratiquement je veux lancer une tache asyncrone et traiter le resultat seulement quand c'est fini !

Je bat encore de l'aile dans ce domaine mais ça va venir :-)
Un conseil expert est bienvenu
Merci !

Exemple : (en commentaire le comportement souhaité et ce qui se passe réellement)

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Test()
    {
      CreateLogin(sLogin, Pwd);
      SetLoginInfo();
    }
    // *************************************************************************
    private  void CreateLogin(string Login,string Pwd)
    {
      var CreateLoginResult = CDB_ConseilleresExtended.CreateLoginAsync(curCons.ID.ToString(), Login, Pwd);
    }

   // ************************************************************
    public static async System.Threading.Tasks.Task<C_ErrorItem> CreateLoginAsync(string Code, string Email, string Pwd)
    {

      HttpClient client = new HttpClient();
      client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json; charset=utf-8");

      Dictionary<string, string> Values = new Dictionary<string, string>();
      Values.Add("Email", Email);
      Values.Add("Password", Pwd);
      Values.Add("ConfirmPassword", Pwd);
      Values.Add("Code", Code);

      var content = new FormUrlEncodedContent(Values);

      var response = await client.PostAsync(MyUri, content);  // Inatendu : RETOUR DIRECT et execution de SetLoginInfo() 

      // Quand SetLoginInfo() a fini on retombe ici mais c'est tout a fait indesirable je devrais pouvoir appeller SetLoginInfo (ou un substitut) UNIQUEMENT quand PostAsync a fini !


      var responseString = await response.Content.ReadAsStringAsync();

      return new C_ErrorItem();
    }