Coffeehouse Post

Single Post Permalink

View Thread: Question on C# Threads
  • User profile image
    blowdart

    OK what do you want to do here? Fire off something into a background task, and wait for it to finish before continuing?

    If that's the case you probably don't need to go as low level as the Thread class, there's a few other options, including BackgroundWorker, Task, Plinq, Async, Lions and Tigers oh may!

    Personally I like Task, but then all my use cases are fire and forget. You can also chain tasks, tor example

    var startTask = new Task(() => SomeMethodSomewhere());
    
    var nextTask = startTask.ContinueWith((t) => SomethingElseThatIsRunAfter());
    
    startTask.Start();
    
    

    Task.WaitAll() then gives you a way to wait for completion.