Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#

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:
Global.background = new Thread(new ThreadStart(() =>
                                    {
                                        while (true)
                                        {
                                            Thread.Sleep(50);
 
                                        }
                                    }
                               ));
 
here Global is a class where i defined the thread as
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 22-Jan-13 19:55pm
Edited 22-Jan-13 20:04pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
Comments
yogesh a sharma at 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 at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
v3
Comments
yogesh a sharma at 23-Jan-13 2:19am
   
thanks sir..but can you provide any simple example of one of the methods of IPC..
Edo Tzumer at 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)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 397
1 OriginalGriff 380
2 Shai Vashdi 280
3 Emre Ataseven 135
4 Abhinav S 128
0 Sergey Alexandrovich Kryukov 8,894
1 OriginalGriff 5,200
2 Peter Leow 3,955
3 Maciej Los 3,535
4 Abhinav S 3,208


Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid