PC Review


Reply
Thread Tools Rate Thread

C# and pipes

 
 
Laurent Navarro
Guest
Posts: n/a
 
      27th Dec 2006
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


 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      27th Dec 2006
Laurent Navarro <(E-Mail Removed)> wrote:
> 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.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Laurent Navarro
Guest
Posts: n/a
 
      27th Dec 2006
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




"Jon Skeet [C# MVP]" <(E-Mail Removed)> a écrit dans le message de news:
(E-Mail Removed)...
> Laurent Navarro <(E-Mail Removed)> wrote:
>> 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.
>
> --
> Jon Skeet - <(E-Mail Removed)>
> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too



 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      27th Dec 2006
Hi,

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

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

--
Ignacio Machin
machin AT laceupsolutions com

"Laurent Navarro" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
Ben Voigt
Guest
Posts: n/a
 
      27th Dec 2006

"Laurent Navarro" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.

>
> Laurent
>
>
>
>
> "Jon Skeet [C# MVP]" <(E-Mail Removed)> a écrit dans le message de news:
> (E-Mail Removed)...
>> Laurent Navarro <(E-Mail Removed)> wrote:
>>> 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.
>>
>> --
>> Jon Skeet - <(E-Mail Removed)>
>> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
>> If replying to the group, please do not mail me too

>
>



 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      27th Dec 2006
Laurent Navarro <(E-Mail Removed)> wrote:
> 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.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
sergejusz
Guest
Posts: n/a
 
      29th Dec 2006

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

Laurent Navarro wrote:
> 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


 
Reply With Quote
 
Laurent Navarro
Guest
Posts: n/a
 
      2nd Jan 2007
Hi Sergejusz,


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

Laurent




"sergejusz" <(E-Mail Removed)> a écrit dans le message de news:
(E-Mail Removed)...
>
> 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
>
> Laurent Navarro wrote:
>> 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

>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pipes in C# =?Utf-8?B?UmljaGFyZEBub3NwYW0ubm9zcGFt?= Microsoft C# .NET 1 22nd Jun 2007 09:01 PM
Using Pipes in C# with Overlapped I/O dvestal@gmail.com Microsoft C# .NET 1 31st Oct 2006 03:21 PM
using pipes for communication el7akika Microsoft VB .NET 6 24th Jan 2005 08:35 AM
Using named pipes in VB.NET John Brook Microsoft VB .NET 1 15th Dec 2004 11:10 PM
Named Pipes vincent Blain Microsoft VB .NET 5 19th Dec 2003 10:32 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:22 AM.