Re: Thread Communication in C#
- From: "Jayme Pechan" <jayme.pechan@xxxxxxxxxxxxx>
- Date: Mon, 16 Jan 2006 08:59:49 -0800
If I use ManualResetEvent, I still need some way to pass data between the
two threads. I guess I could create a queue for each thread but I'm not
sure how to pass the reference to the queue to the sub thread at start. I
thought about making it a static queue but the data must be directed to the
right thread. Any thoughts on how to get past this hurdle? Thanks for your
help.
"Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message news:ezkoxzrGGHA.2652@xxxxxxxxxxxxxxxxxxxxxxx
> Jayme,
>
> Well, if you want a completely managed solution, I would use a
> ManualResetEvent, which is tailored for the thread. This will work only
> if you have a handful of messages you send to each thread (start, stop,
> for example), because you would have to send a different event for each
> message, and wait on those.
>
> You can also make the same calls to GetMessage and PostThreadMessage if
> you wish, making the calls through the P/Invoke layer.
>
> Hope this helps.
>
>
> --
> - Nicholas Paldino [.NET/C# MVP]
> - mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
>
> "Jayme Pechan" <jayme.pechan@xxxxxxxxxxxxx> wrote in message
> news:%23T7SpvrGGHA.1312@xxxxxxxxxxxxxxxxxxxxxxx
>> I've been working on porting an application to C# that was previously
>> written in C++. This application is a windows service application so
>> there is no user interface. I have a number of worker threads in C++
>> that create components and wait for messages from the main thread to
>> process work. This was all done using the PostThreadMessage and
>> GetMessage. I recall that in Unix I used to do this kind of thing with
>> Pipes but I can't figure out how to do this in C#. I need the thread to
>> block until the main thread sends it data to process and that is what the
>> Pipes and GetMessage both did. Any idea what is the correct way to
>> duplicate this behavior in C# managed code? Thanks.
>>
>
>
.
- Follow-Ups:
- Re: Thread Communication in C#
- From: Nicholas Paldino [.NET/C# MVP]
- Re: Thread Communication in C#
- References:
- Thread Communication in C#
- From: Jayme Pechan
- Re: Thread Communication in C#
- From: Nicholas Paldino [.NET/C# MVP]
- Thread Communication in C#
- Prev by Date: Re: Document.Open Office Example
- Next by Date: Re: completely simple question about .NET distributed code
- Previous by thread: Re: Thread Communication in C#
- Next by thread: Re: Thread Communication in C#
- Index(es):
Relevant Pages
|