Ich erhalte immer bei meinem Beispielcode mit der await Operator eine Fehlermeldung
Fehlermeldung:
Der 'Await'-Operator kann nur innerhalb einer Async-Methode verwendet werden. Markieren Sie ggf. diese Methode mit dem 'async'-Modifizierer, und ändern Sie deren Rückgabetyp in 'Task'.
Zum Fehler Code
private void fl_Init_Live()
{
try
{
this.authClient = new LiveAuthClient("0000000012345676"); //cid
LiveLoginResult loginResult = await this.authClient.InitializeAsync(scopes);
if (loginResult.Status == LiveConnectSessionStatus.Connected)
{
this.btnLogin.Content = "Sign Out";
this.liveClient = new LiveConnectClient(loginResult.Session);
//this.GetMe();
}
}
catch (LiveAuthException authExp)
{
//this.tbResponse.Text = authExp.ToString();
}
}
|
Lösung:
Man muß vor die Function die Anweisung async einfügen
Lösungs Code
private async void fl_Init_Live()
{
try
{
this.authClient = new LiveAuthClient("0000000012345676"); //cid
LiveLoginResult loginResult = await this.authClient.InitializeAsync(scopes);
if (loginResult.Status == LiveConnectSessionStatus.Connected)
{
this.btnLogin.Content = "Sign Out";
this.liveClient = new LiveConnectClient(loginResult.Session);
//this.GetMe();
}
}
catch (LiveAuthException authExp)
{
//this.tbResponse.Text = authExp.ToString();
}
}
|