Hello All,

I am in the middle of creating a class that I want to use with Serial IO per
the MVP on this forum.

I am still having trouble with my design process I think.

I created a class that is designed to basically receive messages from the
port. It is a CommEvent
private void port_DataReceived()
{
byte[] data = port.Input;
RxMESSAGE += Encoding.ASCII.GetString(data,0,data.Length);
}

this class is created from a WinCE form.

there suggestion was to create a seperate thread that receives data.
my question(s) in this process is

1)if I have a class that is created from a WinCE form( myThread = new
Utility.myThreadClass(); ) with the event port_DataReceived. Will that event
raise without locking up my WinCE form?

2) how do I start a thread that will allow this event to be raise and allow
me to continue working on my WinCE form? In every other situation I have
written a thread that calls one function, once that function was done the
thread was done also, in this case I am trying to start a thread the allows
an event to fire?

Re: Trouble with Multi Threading by Dan

Dan
Thu Nov 11 06:45:29 CST 2004

I would simply have my event handler with your form, then once the event
handler is created, create and start a new thread to perform the work you
need to, freeing up the main thread should the work be substantial.

"jayderk" <jayderk@hotmail.com> wrote in message
news:ejTTV50xEHA.908@TK2MSFTNGP11.phx.gbl...
> Hello All,
>
> I am in the middle of creating a class that I want to use with Serial IO
> per
> the MVP on this forum.
>
> I am still having trouble with my design process I think.
>
> I created a class that is designed to basically receive messages from the
> port. It is a CommEvent
> private void port_DataReceived()
> {
> byte[] data = port.Input;
> RxMESSAGE += Encoding.ASCII.GetString(data,0,data.Length);
> }
>
> this class is created from a WinCE form.
>
> there suggestion was to create a seperate thread that receives data.
> my question(s) in this process is
>
> 1)if I have a class that is created from a WinCE form( myThread = new
> Utility.myThreadClass(); ) with the event port_DataReceived. Will that
> event
> raise without locking up my WinCE form?
>
> 2) how do I start a thread that will allow this event to be raise and
> allow
> me to continue working on my WinCE form? In every other situation I have
> written a thread that calls one function, once that function was done the
> thread was done also, in this case I am trying to start a thread the
> allows
> an event to fire?
>
>
>
>
>



Re: Trouble with Multi Threading by Ginny

Ginny
Thu Nov 11 09:25:16 CST 2004

There is a Serial class on www.opennetcf.org that does what you want and/or
could serve as an example.

--
Ginny Caughey
.Net Compact Framework MVP



"jayderk" <jayderk@hotmail.com> wrote in message
news:ejTTV50xEHA.908@TK2MSFTNGP11.phx.gbl...
> Hello All,
>
> I am in the middle of creating a class that I want to use with Serial IO
> per
> the MVP on this forum.
>
> I am still having trouble with my design process I think.
>
> I created a class that is designed to basically receive messages from the
> port. It is a CommEvent
> private void port_DataReceived()
> {
> byte[] data = port.Input;
> RxMESSAGE += Encoding.ASCII.GetString(data,0,data.Length);
> }
>
> this class is created from a WinCE form.
>
> there suggestion was to create a seperate thread that receives data.
> my question(s) in this process is
>
> 1)if I have a class that is created from a WinCE form( myThread = new
> Utility.myThreadClass(); ) with the event port_DataReceived. Will that
> event
> raise without locking up my WinCE form?
>
> 2) how do I start a thread that will allow this event to be raise and
> allow
> me to continue working on my WinCE form? In every other situation I have
> written a thread that calls one function, once that function was done the
> thread was done also, in this case I am trying to start a thread the
> allows
> an event to fire?
>
>
>
>
>



Re: Trouble with Multi Threading by Chris

Chris
Thu Nov 11 10:09:29 CST 2004

Inline....

> 1)if I have a class that is created from a WinCE form( myThread = new
> Utility.myThreadClass(); ) with the event port_DataReceived. Will that
> event
> raise without locking up my WinCE form?

Yes. The DataReceived event comes in on a separate thread context - the one
that the serial class is using for listening to the serial line. To affect
the UI from the DataReceived evednt handler, you *must* use Invoke.

> 2) how do I start a thread that will allow this event to be raise and
> allow
> me to continue working on my WinCE form? In every other situation I have
> written a thread that calls one function, once that function was done the
> thread was done also, in this case I am trying to start a thread the
> allows
> an event to fire?

I'd do a couple things.

1. In the event handler, simply append data to a global queue then raise
another event to your app
2. Create a thread that listens for the new event raised in #1, and from
that handler, read from the gloabl queue and do something with it - remember
to use Invoke if you affect the UI.

This will prevent blocking the receiving thread and give the best possible
serial throughput, plus it allows you to monitor and handle incoming data
without blocking the UI.

Sure, it's a bit more complex than linear procedural code, but it's the
right way to make the app robust and responsive.


--
<ctacke/>
www.OpenNETCF.org
Your CF searches start and end here





Re: Trouble with Multi Threading by Daniel

Daniel
Thu Nov 11 10:18:04 CST 2004

That's what I call coincidence :-)

I have just written a blog entry on an example to do exactly that!

Just posted: http://www.danielmoth.com/Blog/2004/11/dont-poll.html

Cheers
Daniel
--
http://www.danielmoth.com/Blog/


"Chris Tacke, eMVP" <ctacke@spamfree-opennetcf.org> wrote in message
news:OEIQUjAyEHA.4028@TK2MSFTNGP09.phx.gbl...
> Inline....
>
>> 1)if I have a class that is created from a WinCE form( myThread = new
>> Utility.myThreadClass(); ) with the event port_DataReceived. Will that
>> event
>> raise without locking up my WinCE form?
>
> Yes. The DataReceived event comes in on a separate thread context - the
> one that the serial class is using for listening to the serial line. To
> affect the UI from the DataReceived evednt handler, you *must* use Invoke.
>
>> 2) how do I start a thread that will allow this event to be raise and
>> allow
>> me to continue working on my WinCE form? In every other situation I have
>> written a thread that calls one function, once that function was done the
>> thread was done also, in this case I am trying to start a thread the
>> allows
>> an event to fire?
>
> I'd do a couple things.
>
> 1. In the event handler, simply append data to a global queue then raise
> another event to your app
> 2. Create a thread that listens for the new event raised in #1, and from
> that handler, read from the gloabl queue and do something with it -
> remember to use Invoke if you affect the UI.
>
> This will prevent blocking the receiving thread and give the best possible
> serial throughput, plus it allows you to monitor and handle incoming data
> without blocking the UI.
>
> Sure, it's a bit more complex than linear procedural code, but it's the
> right way to make the app robust and responsive.
>
>
> --
> <ctacke/>
> www.OpenNETCF.org
> Your CF searches start and end here
>
>
>
>