Skip to content

Async and Wait

January 13, 2016

Was a little stuck on using the async and wait methods from a Task object, here are some examples I got to get it eventually compiling

static void Main()
{
Model db = new Model();

foreach (Client account in db.Clients.Where(x => x.Lic_Type_Id == 0).ToList())
{
// Create task and start it.
// … Wait for it to complete.
Task<string> t1 = Task.Factory.StartNew<string>(() => GreetUser(“Hi”));
t1.Start();
t1.Wait();

//Task task = new Task(ProcessClientAccountAsync(“”));
Task t2 = Task.Factory.StartNew(() => ProcessClientAccountAsync(“Hi”));
t2.Start();
t2.Wait();
}

}

static string GreetUser(string message)
{
return message;
}

static async void ProcessClientAccountAsync(string a)
{
WebApplication.Controllers.AccountController.CreateClientAccount newClientAccount = new Controllers.AccountController.CreateClientAccount(“a”, “b”, “c”);
ActionResult result = await newClientAccount.Execute();
}

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: