Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I call async methods in asp.net C# 4.0?

I'm aware that with .net 4.5 there is the await, async keywords that allows for easy calling of async methods. I 'm currently studying how to make async calls in C# 4.0. An example I want to is to make an async call where the datagrid is being databind.

If you could provide me some links I would really appreciate it.

like image 327
Randel Ramirez Avatar asked Nov 07 '12 09:11

Randel Ramirez


1 Answers

Have a look at using Tasks, this was available in .Net 4 and should help you. A simple example might look like this:

public void MainFlow()
{
   Task taskWork = Task.Factory.StartNew(new Action(DoWork));
   //Do other work
   //Then wait for thread finish
   taskWork.Wait();
}


private void DoWork()
{
   //Do work
}

For more, have a look here

like image 151
Justin Harvey Avatar answered Sep 20 '22 11:09

Justin Harvey