You can put tasks in threads whenever you want them to run:
public abstract class MyTask { public abstract void DoWork(); }
MyTask is an abstract class that represents a task, and defines a DoWork () method that will do what you want. SomeFactoryMethodToCreateATaskInstance () will create a specific instance of the task, and all you have to do is write DoWork () to do what you need to do:
public class Twitterer : MyTask { private string _tweet; public Twitterer(string tweet) { _tweet = tweet; } public override DoWork() { TwitterApi api = new TwitterApi();
You will undoubtedly want to take some action to complete the task. No matter what you do, the task completion routine should be thread safe and probably should be called via BeginInvoke () / EndInvoke () if you need to do any UI-ish work.
SomeTaskStarter () is best called from a Windows service and most likely contains an argument with information about which task should be started, etc.
source share