What are the relative merits (or demerits) for implementing an Erlang-style "Continuation" pattern in C#. I'm working on a project that has a large number of Lowest priority threads and I'm wondering if my approach may be all wrong.

It would seem there is a reasonable upper limit to the number of long-running threads that any one Process 'should' spawn. With that said, I'm not sure what would signal the tipping-point for too many thread or when alternate patterns such as "Continuation" would be more suitable.

In this case, many of the threads do a small amount of work and then sleep until woken to go again (Ex. Heartbeat, purge caches, etc...). This continues for the life of the Process.

  • 1
    If they do a small amount of work and then sleep again, couldn't you just implement them all as a single thread with different possible tasks? This would solve your issue of having may threads Commented Nov 30, 2011 at 20:28
  • Isn't that essentially what the Continuation pattern is? But yes, that's what I'm considering. I'm just concerned about creating something that is too tightly coupled, relating functions that would otherwise never be combined together. That why I'm trying to think through the implications of following such a pattern.
    – JoeGeeky
    Commented Nov 30, 2011 at 20:33
  • TBH, no idea. I've yet to have time to look into Erlang, so couldn't reasonably comment on Erlang-style "Continuation" pattern. Commented Nov 30, 2011 at 20:37

1 Answer 1


A thread model is really more for when a task is continually running. What you're describing is more of an event model. In response to a timer elapsing, you run through a function once, then the timer is reset. You only have enough threads to handle whatever events are running at any given moment, and you can have a ton of pending timers without even noticing.

Continuations are kind of a workaround to allow you to retain state in functional programming, but retaining state is what objects are all about. Store whatever you need in a field, and it will be available to you the next time the event fires.

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.