Is there any way of decorating a method with an attribute to be executed in other thread
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 reco开发者_如何学运维de them again, an attribute would let me choose from sync, to async smoothly. Any ideas or workaround?
thanks.
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
精彩评论