Questions about Migration and Async
Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2012
Forum Discription: For .NET 4.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3891
Printed Date: 08-Apr-2025 at 3:10am
Topic: Questions about Migration and Async
Posted By: iDave
Subject: Questions about Migration and Async
Date Posted: 14-Jan-2013 at 6:15pm
Good day,
I've migrated from 2010 to 2012 and some code doesn't work. All of them related to async. So, I wonder if someone could be so kind to give me a hint here.
For example:
Here's what I was doing back in 2010:
public void GetCustomers(Action<IEnumerable<Customer>> onSuccess, Action<Exception> onFail) { Manager.Customers .Include(c => c.Address) .OrderBy(c => c.Id) .ExecuteAsync( op => { if (op.CompletedSuccessfully) { if (onSuccess != null) onSuccess(op.Results); } else { if (onFail != null) { op.MarkErrorAsHandled(); onFail(op.Error); } } } ); }
|
How should I convert it to 2012 in order to have this code working again?
Thanks in advance!
|
Replies:
Posted By: smi-mark
Date Posted: 14-Jan-2013 at 6:32pm
Hi,
I would suggest you read up on Tasks, it replaces coroutines. Essentially the code would look like this:
public Task<IEnumerable<Customer>> GetCustomers() { return await Manager.Customers .Include(c => c.Address) .OrderBy(c => c.Id) .ExecuteAsync(); }
I just typed that up in notepad, so I may be slightly off. As you can see it is a lot less code.
In your VM you can then write code like this:
var customers = await Repository.GetCustomers();
you can also wrap try statements around them now, unlike coroutines. ie:
try { await MyRoutine(); } catch (MyException ex) { }
etc
I would strongly advise looking at the TempHire and other examples that have been updated to DF 2012
|
Posted By: smi-mark
Date Posted: 14-Jan-2013 at 6:35pm
If you can't upgrade all your code right now, you can use the compatibility pack.
This link will explain it:
http://drc.ideablade.com/devforce-2012/bin/view/Documentation/cocktail-backward-compatibility
|
Posted By: iDave
Date Posted: 14-Jan-2013 at 6:38pm
Thank you for your lighting-fast reply!
Indeed, the code is more shorter and clean.. I'm now taking a look at TempHire sample and will look forward to the Compatibility Pack if the there's a lot of code and no time to upgrade all.
Thanks again!
Regards, Dave
|
|