1

Is there any way of decorating a method in .NET with an attribute which would mean the method will be executed in other thread?

I have a lot of methods that I would like to execute in other thread but I don't want to recode them again, an attribute would let me choose from sync, to async smoothly. Any ideas or workaround?

thanks.

k-dev
  • 1,657
  • 19
  • 30

1 Answers1

1

The framework has no such attribute.

In any case you don't have to recode the method you are invoking, but the invoker. You can always use a delegate to create a async invocation or better yet use a Task. Just make sure you are taking care of syncronization issues. The following link contains excellent info on the subject: http://www.albahari.com/threading/ and here: How to create an asynchronous method
Community
  • 1
  • 1
Klinger
  • 4,900
  • 1
  • 30
  • 35
  • Is it possible to make a custom one? – k-dev Jul 21 '11 at 19:47
  • You can find some info here: http://social.msdn.microsoft.com/Forums/en-US/async/thread/8638275c-cfb3-40cb-8c32-ee55f22319ac/ – Klinger Jul 21 '11 at 19:51
  • Look at AOP. Good info here: http://stackoverflow.com/questions/25803/how-do-i-intercept-a-method-call-in-c and here: http://programmersunlimited.wordpress.com/2011/04/07/method-waitretry-functionality-using-postsharp/ – Klinger Jul 21 '11 at 19:58