开发者

C# - How to access a remote thread?

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, 开发者_C百科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.


I don't think that it's right approach. Will be better to have interface in service that will provide functionality to menage threads.


I would communicate to the process via TCP or .NET remoting with the parameters needed to define the task to perform.

Then you will need a class that manages this requests and communicates to the threads telling them what to do.


I would not use the thread id. The thread name is a possibility, but I would lean toward providing a name for each task and keying on that.

If I were tackling this problem, I would expose a Window Communication Foundation (WCF) interface on your Windows service. Your application would then control the tasks through that interface.

I would avoid using .NET Remoting. It will work, but .NET Remoting has been superseded by WCF. From the MSDN article:

WCF supersedes several earlier Microsoft technologies for creating distributed applications. Most applications that would have been built using ASP.NET Web Services, .NET Remoting, Enterprise Services, System.Messaging, or WSE will instead be built on WCF.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜