简体   繁体   English

C# 不包含“GetAwaiter”的定义,并且最佳扩展方法重载需要“Task”类型的接收器

[英]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.我正在尝试制作 GTA 5 Cheat 我已经完成了注射器并正在处理 UI。 I have tried to delete await taskAwaiter;我试图删除 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();
}

The await operator isn't meant to be used with an awaiter - it calls GetAwaiter itself (if necessary). await运算符不打算与 awaiter 一起使用 - 它会调用GetAwaiter本身(如有必要)。

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 .在此代码的每种情况下, await运算符都用于task ,而不是awaiter

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “T”不包含“Foo”的定义,最好的扩展方法重载需要“IType”类型的接收器 - 'T' does not contain a definition for 'Foo' and the best extension method overload requires a receiver of type 'IType' HttpResponseMessage' 不包含 'GetAwaiter' 的定义,并且没有可访问的扩展方法 'GetAwaiter' - HttpResponseMessage' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' 不包含“GetAwaiter”的定义,并且没有可访问的扩展方法“GetAwaiter”接受“List”类型的第一个参数 - does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' accepting a first argument of type 'List 最好的扩展方法重载需要一个 List 类型的接收器 - The best extension method overload requires a receiver of type List Task<> 不包含“GetAwaiter”的定义 - Task<> does not contain a definition for 'GetAwaiter' 数据库集<tablename>不包含“Where”的定义和最佳扩展方法重载</tablename> - DbSet<TableName> does not contain a definition for 'Where' and the best extension method overload IEnumerable <Entity> &#39;不包含异步任务方法的&#39;GetAwaiter&#39;定义 - IEnumerable<Entity>' does not contain a definition for 'GetAwaiter' for Async Task Method c# 不包含定义和扩展方法 - c# does not contain a definition for and no extension method 不包含&#39;GetAwaiter&#39;的定义 - does not contain a definition for 'GetAwaiter' “int”不包含“Contains”的定义和最佳扩展方法重载“Queryable.Contains” - 'int' does not contain a definition for 'Contains' and the best extension method overload 'Queryable.Contains
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM