0

I'm using the publish subscribe pattern inside a WCF environment.

When I want to publish a message from the pub\sub service to the subscribers

i'm doing it by using reflection.

i'm invoking the methods one by one using foreach.

How can I do this operation async?

thanks

3
  • Why reflection? Post your code... Also, check this stackoverflow.com/questions/8383439/… Dec 5, 2011 at 9:59
  • I'm using pipe binding, I guess post is not working for that. am I wrong? for now I'm using Parallel.ForEach.
    – Guy
    Dec 5, 2011 at 10:19
  • can you share your code? Dec 5, 2011 at 12:12

1 Answer 1

0

If you would like to run each method invocation asynchronously and don't care about return values you can just spin of each one of them on a new thread pool thread, for example using System.Threading.ThreadPool.QueueUserWorkItem(WaitCallback).

If you're in a more advanced scenario, there's the TPL (Task Parallel Library), Rx.NET (Reactive Extensions) and other more structured and capable ways of doing this.

2
  • I'm using Parallel.ForEach(), do you have a better solution? maybe which not using reflection?
    – Guy
    Dec 5, 2011 at 10:22
  • For what my answer was intended, Parallel.ForEach works in the same way. However, it has little do to with how you invoke your methods, whether it be using reflection or some other dynamic technique. Is this was you're really asking; how to dynamically invoke methods?
    – lbergnehr
    Dec 5, 2011 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.