如何在c#中调用异步方法并显示输出?

时间:2017-10-22 17:40:09

标签: c#

我正在尝试运行_Main方法并在控制台中显示输出。但它没有显示输出。你能告诉我问题出在哪里吗?

{

    public View_files()
    {
        InitializeComponent();
    }
    static async Task _Main()
    {
        List<string> fList = new List<string>();
        IMongoClient client = new MongoClient("mongodb://localhost:27017/");
        IMongoDatabase database = client.GetDatabase("mymongodb");
        IMongoCollection<BsonDocument> collection = 
        database.GetCollection<BsonDocument>("store");
        BsonDocument filter = new BsonDocument();
        filter.Add("UserID", "abc");
        using (var cursor = await collection.FindAsync(filter))
        {
            while (await cursor.MoveNextAsync())
            {
                var batch = cursor.Current;
                foreach (BsonDocument document in batch)
               {
                    Console.WriteLine(document.GetElement("FileID"));

                }
                Console.Read();               
            }
        }
    }
    private void button1_Click(object sender, EventArgs e)
    {
        _Main().Wait();
    }

}

0 个答案:

没有答案