gpt4 book ai didi

c# - 等待/异步引用错误

转载 作者:可可西里 更新时间:2023-11-01 08:03:31 28 4
gpt4 key购买 nike

我正在尝试在某些返回字符串的函数中执行一些异步操作。

async private void button1_Click(object sender, EventArgs e)
{
string output = await thr_calc(this, null);
}

async private Task<string> thr_calc(object sender, EventArgs e)
{
return await zzztest();
}

string zzztest()
{
string asd;
//some stuff here
return asd;
}

但它在每个包含单词 async/await 的字符串上给我错误!我在 Windows 桌面上使用俄语版的 ms vs express 2012,所以这里是错误的翻译:

Cannot find all types required by the 'async' modifier. Are you targeting the wrong framework version, or missing a reference to an assembly?

还有 2 个错误:

Predefined type 'System.Runtime.CompilerServices.IAsyncStateMachine' is not defined or imported

我找不到那个引用。我之前尝试过使用 async/await 并且它工作正常,现在我在做所有相同的事情,但它不是。我缺少什么?

最佳答案

  • 在 thr_calc 中,使用:

    return zzztest()
  • 此外,请确保您已将项目设置为使用 .Net 4.5 或更高版本(那是引入“异步”的时间)

关于c# - 等待/异步引用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15575253/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com