0
私はasync await
をC#で頭の中に入れようとしています。私は2つのファイルを持つこの小さなWindowsコンソールアプリケーションを書いています。C#のmainからasync関数を呼び出す
Downloader.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace AsyncAwait
{
public class Downloader
{
public async Task DownloadFilesAsync()
{
// In the Real World, we would actually do something...
// For this example, we're just going to print file 0, file 1.
await DownloadFile0();
await DownloadFile1();
}
public async Task DownloadFile0()
{
Console.WriteLine("Downloading File 0");
await Task.Delay(100);
}
public async Task DownloadFile1()
{
Console.WriteLine("Downloading File 1");
await Task.Delay(100);
}
}
}
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AsyncAwait
{
class Program
{
static void Main(string[] args)
{
Downloader d = new Downloader();
}
}
}
私はちょうど私のmain
から機能DownloadFilesAsync()
を呼びたいです。私はDownloader
オブジェクト 'd'を作成しました。しかし、それは主で戻り型は空でなければならないので不可能である。これを回避する方法は何ですか?
https://www.bing.com/search?q=calling+an+async+function+from+main+in+c%23 –