How to make any function Async/Await

  • Thread starter Thread starter Sudip_inn
  • Start date Start date
S

Sudip_inn

Guest
see a sample function

public static void Method2()
{
for (int i = 0; i < 25; i++)
{
Console.WriteLine(" Method 2");
}
}



tell me how to make this function async await ?

if function is void too.

again see the below function

static async Task<int> ReadFile(string file)
{
int length = 0;

Console.WriteLine(" File reading is stating");
using (StreamReader reader = new StreamReader(file))
{
// Reads all characters from the current position to the end of the stream asynchronously
// and returns them as one string.
string s = await reader.ReadToEndAsync();

length = s.Length;
}
Console.WriteLine(" File reading is completed");
return length;
}

await is used with in function but some time we may not be able to see await inside function then how could i make that function async await ? give one example please

some link i got

Async And Await In C#
The Simplest Way to Create an Asynchronous Method -- Visual Studio Magazine
Understanding Control Flow with Async and Await in C# | Pluralsight

Continue reading...
 
Back
Top