简体   繁体   中英

Starting and Stopping concurrent threads through Windows Service

I am new to .NET environment. I need a windows service whose Start and Stop method will call a specific class, say MainContext's Start and Stop method respectively. The MainContext class will contain the list of extensions loaded through MEF . Each extensions needs to be run as a separate thread in concurrent manner.

The class MainContext will contain two public methods Start and Stop , both of return type void and containing no arguments. On calling Start method, it will start the thread for each extensions loaded through MEF in an concurrent manner. While the Stop method will stop all the threads started by Start method.

Which is the best threading practice in this situation? I am confused. Should I use System.Threading.Tasks.Task class or System.Threading.Thread class for multi-threading or should I use any other technique? Which would be better suited to my requirements and would provide me more flexibility and stability?

I've done something similar using MAF, with add-ins watching file servers, databases, and web services. The Windows service invokes Start and Stop methods in each add-in, which in turn enable or disable System.Timer.Timers. The actual processing is done on each timer's elapsed event handler, which runs on a pooled thread.

One of the add-ins watches a database table that's used inter-process communication so that I can monitor and control the other add-ins from a UI app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM