0

so I'm pretty new to c# and I've came around this problem: I have some methods that invoke different delegates (with potentially different argument types). However these delegates shouldn't be called right away. If the main Thread is running a delegate, they should run afterwards, kinda like queuing the delegate and running it later.
Now I could probably use DynamicInvoke but I don't know if it will slow the queue down too much, besides I know what the delegate type is and what kind of parameter it should look for, so its not really runtime dependent. Please help me if you can, I really need an answer.

Thanks everybody (who responds)

Yamcha
  • 1,264
  • 18
  • 24

2 Answers2

1

One of the ways is doing that could be use of Tasks (beginning from .NET 4.0)

Can have a look on

Asynchronous methods, C# iterators, and Tasks

how to create scheduling tasks, like, seems, in your case.

Hope this helps.

Tigran
  • 61,654
  • 8
  • 86
  • 123
  • Sorry, I can only use .net 3.5 – Yamcha Apr 07 '12 at 20:47
  • at this point may be more appropriate could be actually an option offered in comment, so [Reactive Extensions](http://msdn.microsoft.com/en-us/data/gg577609) – Tigran Apr 07 '12 at 20:53
  • @user1316459: there is actually another solution yet, may be more apporiate for *scheduling*, it's a [Quartz.NET](http://quartznet.sourceforge.net/). Have a look on it, could be more useful for you. – Tigran Apr 07 '12 at 20:58
1

Would it work if, instead of adding your delegates directly, you wrapped them into new Action delegates which simply invoke them, passing all their parameters? For example:

List<Action> pending = new List<Action>();
pending.Add(() => MethodThatTakesNoParameters());
pending.Add(() => MethodThatTakesOneParameter(param));
pending.Add(() => MethodThatTakesThreeParameters(param1, param2, param3));
Douglas
  • 53,759
  • 13
  • 140
  • 188