0

I have the following code:

ThreadStart starter;
Thread worker_thread = null;

starter = Work;
starter += () => { AnotherWork();};
worker_thread = new Thread(starter) { IsBackground = true };
worker_thread.Start();

I wanted to make sure that AnotherWork function is run only after Work function is done executing. But I am not sure if this code will do as intended.

  • 1
    It is easier to use the task library for this, check out [this answer regarding chaining of tasks](https://stackoverflow.com/a/11649686/1145403) – Lennart Stoop Feb 17 '18 at 11:39

1 Answers1

0

Today, threads in C# is kind of legacy that was added into the language just by inertia. Instead, you may consider async/await approach or Task.ContinueWith()

I just strongly recommend "A Tour of Task" by Stephen Cleary, series of brillian posts describing that in full details: https://blog.stephencleary.com/2014/04/a-tour-of-task-part-0-overview.html

Yury Schkatula
  • 5,291
  • 2
  • 18
  • 42