I would like to write Async to 2 files some data, i've tried something like this:
private static void Main(string[] args)
{
FileStream file1 = File.Create(@"D:\test\plik1.dat");
FileStream file2 = File.Create(@"D:\test\plik2.dat");
var f1 = await write(file1);
var f2 = await write(file2);
for (int i = 0; i < 1024 * 1024; i++)
{
if (i % 100 == 0)
Console.Write("X");
}
}
private static async Task write(FileStream fs)
{
var zap = new StreamWriter(fs);
for (long i = 0; i < 1024 * 1024 * 250; i++)
{
zap.WriteAsync("xxx");
}
}
The compiler error is:
The 'await' operator can only be used within an async method.
how to do it properly?
i would like also to do loop instruction with console.Write("X);
as async
can someone help me ? i couldn't find some basic examples on google...