-1

I need to write a code using c# 3.5 where 2 threads simultaneously run on 100s of folders. When first thread completes processing a folder, it inputs folder name to 2nd thread so that it executes its logic on 1st folder. But one issue I face is that 2nd thread should run like a queue due to a restriction on database.

thread1.start() for folder 1 thread2.start(folder1): Need to create a queue for thread2 so that only one folder is in process by thread2.

I got stuck due not many options are available in 3.5 framework. Thank you for help in advance.

  • This is called the [Producer-Consumer pattern](http://www.dotnetcurry.com/patterns-practices/1407/producer-consumer-pattern-dotnet-csharp) and there are many [solutions available in .NET](https://stackoverflow.com/questions/733793/). – Dour High Arch Feb 12 '18 at 18:00

1 Answers1

0

For this kind of job, IMHO you better raise an event in the first thread when folder processed and inside that event run second thread for continue your process. I'm including link to msdn article that explains creation of the event with custom arguments. https://msdn.microsoft.com/en-us/library/5z57dxz2(v=vs.90).aspx

Yuri
  • 2,820
  • 4
  • 28
  • 40