0

In one application, I'm starting up a thread as follows:

System.Threading.ThreadStart ts = new System.Threading.ThreadStart(ReceiveInformation);
this._receiveThread = new System.Threading.Thread(ts);
this._receiveThread.Name = "MSMQ Receive Thread";
this._receiveThread.Start();

In another application, I'd like to access that thread, I was thinking something of:

System.Process other_Process = System.Process.GetByname("Name of the other process");
System.Threading.Thread = System.Threading.GetByName(other_Process, "MSMQ Receive Thread");

I am aware that my source code is complete bogus (I can hear you laughing about my naïve attempt :-) ), can anybody tell me what's the right way to do this?

Thanks in advance

Dominique
  • 16,450
  • 15
  • 56
  • 112
  • Does this answer your question? [Get list of threads](https://stackoverflow.com/questions/10315862/get-list-of-threads) – Sinatr Jun 22 '21 at 09:19
  • 2
    @Sinatr he wana get thread from another process not the same – Selvin Jun 22 '21 at 09:20
  • See Rotem's answer to [this](https://stackoverflow.com/questions/19090743/list-running-threads-of-an-external-process) post – auburg Jun 22 '21 at 09:21
  • 5
    Why you need this? seems like a XY problem ... – Selvin Jun 22 '21 at 09:23
  • 2
    "*I'd like to access that thread*" <== Could you elaborate on this? What kind of access would you like to achieve? – Theodor Zoulias Jun 22 '21 at 09:27
  • `I'd like to access that thread` why? While you can use [Process.Threads](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.threads?view=net-5.0) to get a list of threads, you can't do anything with them. If you want to do anything useful you'll have to communicate with the other process and tell it what you want. If you use any TCP-based method (sockets, HTTP listener, gRPC), all you need to know is the port the other process listens on – Panagiotis Kanavos Jun 22 '21 at 09:47
  • `I don't know how to check if anything arrives at my "Receive" thread.` add some logging? – Panagiotis Kanavos Jun 22 '21 at 09:50
  • @PanagiotisKanavos: add logging to which method? When I add a breakpoint in the `ReceiveInformation()` method, the breakpoint doesn't get hit. So, where should I start? – Dominique Jun 22 '21 at 09:53
  • So your *real* problem is sockets and why nothing is received. This has nothing to do with threads. You didn't post any socket-related code, so we can't guess what's going on. – Panagiotis Kanavos Jun 22 '21 at 10:01

2 Answers2

2

I think you need to change your point of view. What you need here is a communication protocol between your applications. This protocol can let you to control from an application the behaviour of another (and its threads too). Further this approach is cross boundaries and not limited to the same PC

Marco Beninca
  • 605
  • 4
  • 15
0

If you want to make your project on a microservice platform you don't need to access other application threads. Just you must make publisher and consumer services. Any way you use MSMQ, RabbitMQ, NServiceBus, Kafka, etc... But I suppose that you should use Mass transit tools because you can switch to various service buses easily.