C# - 在主函数中使用异步

标签 c# visual-studio

根据这篇文章,投票最高的答案建议我们可以直接在 main 中使用异步。还是我理解错了?

Can't specify the 'async' modifier on the 'Main' method of a console app

我的主课:

public class Program
{
    public static async Task Main(string[] args)
    {
        ApproveEvents ap = new ApproveEvents();
        List<MyModel> result = new List<MyModel>();
        result = await ap.ApproveAsync();
        if (result.count > 0)
        {
            //do something here
        }

    }
}

还有,

public class ApproveEvents
{
    public async Task<List<MyModel>> ApproveAsync()
    {
        //blah blah
    }
}

Visual Studio 2017 提示入口点没有 Main 方法

我该如何解决?

最佳答案

async Task MainC# 7.1 中可用.您可以在 build properties 中更改它(默认是最新的大版本,也就是7.0)

关于C# - 在主函数中使用异步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51626861/

相关文章:

c++ - 为什么 Visual Studio Performance Profiler 不显示帧时间和 FPS 的任何内容?

visual-studio - 颠覆 : How to organize svn tags for Visual Studio solutions -- or -- How to version an entire VS solution

c# - Appointment.Save 和 Appointment.Update 始终将 IsMeeting 设置为 true

C# - 将文本文件作为类加载

c# - 如何从 C# 将 int 对列表输入到 MySQL 存储过程?

c# - 如何将此 Linq SQL 编写为动态查询(使用字符串)?

c# - SQL C#,命令(查询)执行两次

c# - 列表的 Ajax BeginForm 仅返回模型的第一个元素或 null

c# - 带有 DoxyGen 的 Visual Studio 用于文档,还是我们应该使用其他东西?

c - 对于 C,Visual Studio-2017 如何调试读取文本文件并在该文本文件后面打印输出的代码?