.net - Generated asynchronous method calls in C# - AOP? -


i working on wpf application uses businesslogic layer (currently single dll) in created bl methods called directly ui. each bl manager resolved unity (thinking on switching mef though...). bl classes implements specific interface have of course apropriate methods.

now, want create (or rather generate) new asynchronous-aspect-like assembly (or more...) should have similar methods/operations defined in original assembly (the same parameters...) , callback delegate parameter. want async methods generated framework out there...

besides usual call to: user userbo = resolve().login("name", "pass"); i'd use similar with: resolve().login("name", "pass", delegate(object, someargs e) { user userbo = e.args....};

now, want assembly generated instead of writing new eventargs , delegates each method. aware postsharp in aop task, coulnd't find regarding code generation mechanism in new dll asynchronous methods.

is there way achieve using third party tool or have rewrite whole async thing manually?

any ideas welcome. thank you.

i'm not aware of tool you, there's easy way wrap them in task objects. easier @ least manually defining async methods , event callbacks.

the general concept run method task , schedule task continuation ui thread.

first, define scheduler (you don't need every time; global var or window-level var):

taskscheduler ui = taskscheduler.fromcurrentsynchronizationcontext(); 

then when want call method , handle return value:

var bll = resolve(); task.factory.startnew(_ => bll.login("name", "pass"))   .continuewith(task =>   {     // note: accessing result raise exceptions thrown login     user userbo = task.result;     ...   }, ui); 

it's not quite pretty suggested syntax, it's usable. task continuation passed continuewith run on ui thread, safe update ui or databound objects.

task objects support other common asynchronous scenarios, in particular cancellation , progress reporting.

since approach doesn't add events class, should possible write t4 template generate extension methods (e.g., logintask(string username, string password, action<task<user>> continuation)).


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -