Azxrxo
Azxrxo

Reputation: 21

C# does not contain a definition for 'GetAwaiter' and the best extension method overload requires a receiver of type 'Task'

I am trying to make a GTA 5 Cheat I have the injector done and am working on the UI. I have tried to delete await taskAwaiter; from my code and it would not launch at that point My code:

TaskAwaiter<string> taskAwaiter = (await MainWindow.client.PostAsync("https://pastebin.com/Mypaste", new FormUrlEncodedContent(nameValueCollection))).Content.ReadAsStringAsync().GetAwaiter();
if (!taskAwaiter.IsCompleted)
{
    await taskAwaiter;
    TaskAwaiter<string> taskAwaiter2;
    taskAwaiter = taskAwaiter2;
    taskAwaiter2 = default(TaskAwaiter<string>);
}
if (taskAwaiter.GetResult() != "success")
{
    this.UpdateStatus("Auth failed");
    this.TimeoutReset();
    this.cant_click = false;
}
else
{
    this.UpdateStatus("Logged in");
    File.WriteAllText(this.auth_file, this.user.ToString());
    this.Download();
}

Upvotes: 0

Views: 1043

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1503789

The await operator isn't meant to be used with an awaiter - it calls GetAwaiter itself (if necessary).

It's not really clear what you're trying to achieve here, and this looks like half-decompiled code, but I suspect you just want something like:

using (var response = await MainWindow.client.PostAsync("https://pastebin.com/Mypaste", new FormUrlEncodedContent(nameValueCollection)))
{
    var text = await response.Content.ReadAsStringAsync();
    if (text == "Success")
    {
        UpdateStatus("Logged in");
        File.WriteAllText(auth_file, user.ToString());
        Download();
    }
    else
    {
        UpdateStatus("Auth failed");
        TimeoutReset();
        cant_click = false;
    }
}

In each case with this code, the await operator is used on a task, not on an awaiter.

Upvotes: 4

Related Questions