Skip to content

Instantly share code, notes, and snippets.

@varun-r-boop
Created December 30, 2022 08:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save varun-r-boop/0c1b13e6d90489dc662a46c35978b248 to your computer and use it in GitHub Desktop.
Save varun-r-boop/0c1b13e6d90489dc662a46c35978b248 to your computer and use it in GitHub Desktop.
Asynchoronus Programming:
using System.Threading.Tasks;
namespace AsyncExample
{
public class Program
{
public static async Task Main(string[] args)
{
// Call an async method and wait for it to complete
int result = await AsyncMethod();
Console.WriteLine(result);
}
public static async Task<int> AsyncMethod()
{
// Run some code asynchronously
int result = await Task.Run(() => {
// Simulate a long-running task by sleeping for 2 seconds
System.Threading.Thread.Sleep(2000);
return 42;
});
// Return the result
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment