Asynchronous Method Invocation

Share with us how you use PostSharp, or how you would like to use it.

Asynchronous Method Invocation

Postby zwan on Wed Jan 16, 2008 12:32 am

I'm new in AOP and perhaps I'm saying a nosense but I'd like to implement an attribute that executes one method Asynchronously and executes the callback at the end of te Asynchronous process.

For Example
....

[ASYNC(FinalMethod=Endrocess)]
private void DoSomeWork()
{
//Long Task...
}

private void EndProcess()
{

MessageBox.Show("Process Finished");

}

Any Idea?
zwan
 
Posts: 1
Joined: Wed Jan 16, 2008 12:19 am
Full Name: juan Antonio

Re: Asynchronous Method Invocation

Postby gfraiteur on Wed Jan 16, 2008 9:20 am

Juan,

Using OnMethodInvocationAspect, it is possible to execute a long method inside a different thread (you surely want to run it outside the GUI thread), and display a message when it's done. Do not forget to 'serialize' the call to MessageBox to the GUI thread, however.

Actually, OnMethodInvocationAspect gives you a delegate to the method being invoked, then it's yours to do what you want -- and it's pretty much general .NET WinForms programming.

Gael
Gael Fraiteur, project leader
got good support? consider donating to the project.
gfraiteur
Site Admin
 
Posts: 608
Joined: Tue Dec 18, 2007 3:09 pm
Full Name: Gael Fraiteur
Company: postsharp.org


Return to What To Do With PostSharp?