First I’m going to explain what I’m trying to do, before asking the question directly. Basically, there is a Windows Service running on a specific machine, let’s call it M1. This Windows Service runs a set of tasks using threads (1 thread for each partition of tasks). I need to program a functionality that will let the user stop/suspend/restart a partition from the administration panel of the application. My solutions consists in accessing those threads by their id/name. Once I have the thread I can do the right operation on it. Is it the right approach?
If yes, how do we do that? The threads are running in M1 and I need to access them from a remote computer (situated in the same network area). Is it even possible?
Thank you. Don’t hesitate to ask for more explanations if needed.
Giving direct control over thread management to a remote process is a hazardous way to solve this. You could set up a thread that listens for requests to suspend, etc., and manipulate the threads on behalf of the requester. But this can cause endless problems since you don’t know what state the thread is in when you suspend it. In particular, it could have locks held, or be in the middle of a database transaction.
If tasks are short-lived, have each thread request work from a boss whenever it completes its current chore. To suspend a partition, tell the boss (via TCP, web services, or whatever) not to give the partition’s thread any more work until further notice.