C# and pipes

L

Laurent Navarro

Hello,


I'm currently working on a multi threaded application and I would like
to create a pipe to communicate between them: the main thread will write
into the pipe some data and the working threads will read and execute. But
it seems that pipes don't exist in C# unless you create your own k,class.

I need to pass object reference between my threads so my first question
is: how do I get the reference (IntPtr) of a managed object ?

I had the idea to use a MemoryStream to write my IntPtr in because this
class is thread safe. Is it a good idea ? Did someone already tackled this
kind of problem ?

Thanks for any help ! :)


Laurent
 
J

Jon Skeet [C# MVP]

Laurent Navarro said:
I'm currently working on a multi threaded application and I would like
to create a pipe to communicate between them: the main thread will write
into the pipe some data and the working threads will read and execute. But
it seems that pipes don't exist in C# unless you create your own k,class.

I need to pass object reference between my threads so my first question
is: how do I get the reference (IntPtr) of a managed object ?

Why not just use a list of Object references? You don't need the IntPtr
at all.
 
L

Laurent Navarro

Hi Jon,

OK I see your point, but if I want to use a list of object, I will have
to manage the multiple thread calls by myself with mutex, won't I ?

Thanks for your answer anyway.

Laurent
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

You could use a synced queue, did you try it ?

I use this kind of structure for a multithreaded TCP/IP server
 
B

Ben Voigt

Laurent Navarro said:
Hi Jon,

OK I see your point, but if I want to use a list of object, I will have
to manage the multiple thread calls by myself with mutex, won't I ?

Thanks for your answer anyway.

Take a look at System.Collections.Queue.Synchronized() method.
 
J

Jon Skeet [C# MVP]

Laurent Navarro said:
OK I see your point, but if I want to use a list of object, I will have
to manage the multiple thread calls by myself with mutex, won't I ?

If you've got shared data, you'll need to manage the threading anyway.
It's not too hard though - and just managing threading for a single
queue is very easy.

See http://www.pobox.com/~skeet/csharp/threads for more threading info.
 
S

sergejusz

Hi Laurent,
I've developed very simple in use class library to make multithreaded
application development easier. Threads in this library communicate
using messages. Message can contain 'everything' you want. If I
correctly understand your problem - it may help you.
You'll find source codes with examples in vb.net and c# here:
http://www.sergejusz.com/boss_workers.htm
Kind regards
Sergejus
http://www.sergejusz.com
 
L

Laurent Navarro

Hi Sergejusz,


I'll give a look at your custom class, thanks for the link !

Laurent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top