Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

Hi This is yogesh sharma and i have developed client server windows application using c#. Now i have started a thread named thread1(which ends when i quit the programme) on the load event of the mdi form.
My problem is that i need to get the state of thread1 when i have started another instance of same application on same or another PC.
My code is below.
On my mdi form my code is:
C#
Global.background = new Thread(new ThreadStart(() =>
                                    {
                                        while (true)
                                        {
                                            Thread.Sleep(50);

                                        }
                                    }
                               ));


here Global is a class where i defined the thread as
C#
public static Thread background;


i need to know the state of the background thread thread1(running,unstarted,stopped etc) from another instance of the application..Please help how could i share global.backgound from each instance of my application..Any Help will be appreciated...
Posted
Updated 22-Jan-13 20:04pm
v2

Not possible: threads live inside of processes - once a process dies, the threads die too.
You might design a service oriented architecture (SOA):
- one service holds the state (your thread)
- the GUI instances communicate with the service
Cheers
Andi
 
Share this answer
 
Comments
yogesh a sharma 23-Jan-13 2:11am    
Thnks for reply but is it possible to know that if thread is alive when it is really in procces, from another instance???
Andreas Gieriet 23-Jan-13 4:34am    
In SOA: you will design an interface that allows to ask for it. Keep in mind: having a thread is an implementation detail - noone outside wants to know and you do not want to expose that information. There must be some meaningful *behaviour* question you want to ask. E.g. server.IsReadyForXXX, etc.
Cheers
Andi
Hello Yogesh,

You can not share the threads in your example since when you start another instance of the EXE, you create a different process for it to run in.
Each process uses it's own memory "space".

You may re-think creating a second process OR you can one of the various methods for Inter-Process Communication (IPC), for example:
- Named Pipes
- Shared Mem
- MSMQ
- Sockets


Cheers,
Edo
 
Share this answer
 
v3
Comments
yogesh a sharma 23-Jan-13 2:19am    
thanks sir..but can you provide any simple example of one of the methods of IPC..
Joezer BH 23-Jan-13 2:35am    
Sure, click on "MSMQ" in the solution above (added link).

Cheers,
Edo

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900