Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multithreading (Communication) 1

Status
Not open for further replies.

Akusei

Programmer
Jul 15, 2003
90
US
I'm making a Windows Service which spawns an undertermined number of threads and a Windows Application that reports the status of each thread. By status I mean stuff that I could only get by "polling" the thread and receiving some details that I want for instance:

Thread #1 is iterating through a list of clients and recording their data, there are 200 clients and the thread knows this, but my windows application does not. I want to be able to "ask" the thread how many client there are total and what client number it is currently recording.

is this possible?

Best Regards,
Nathan Martini
 
ummm... a thread can only do one thing at a time... so it can't be recording their data and respond to a query (poll) from another thread or process, at the same time.

A thread can at intervals of it’s own making, check for requests (messages) and respond to them. Of course during this activity it is not recording their data or anything else.

Or a thread could, if it could locate said process, send status information to the remote process using some form of inter-process communications at a time of it’s own choosing. This is not at all uncommon and the technique is frequently used for logging purposes.


-pete
 
That sounds like it would work perfectly... Do you know of a good article or tutorial on making inter-process communication?
 
Well i am partial to using sockets for inter-process communications but in the .NET world perhaps remoting would be simpler.

If you decide to research sockets try
To research .NET remoting go to msdn.microsoft.com


-pete
 
You can use a shared object to transfer data, but you must implement some locking to prevent simultaneous access. See the Interlocked class:

ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconinterlocked.htm

If you need to do more than set a simple value, you want the Monitor class. The .NET Developers Guide has good information on this:

ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconmonitor.htm

Chip H.
 
Not to sound uneducated or anything, but I've never used links like "ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconinterlocked.htm". How would I go about getting to this information?

Thanks
 
These are links to the online help within Visual Studio. If you have it loaded, you can paste it into a browser, or paste it into the help address box in your VS toolbar.

If you're running off the .NET sdk (command-line compiler), you'll have to go to the MSDN web site and search within .NET framework for "Monitor" and "Interlocked".

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top