CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: Thread advice

  1. #1
    Join Date
    Jul 2002
    Posts
    30

    Question Thread advice

    Hi,

    I'm developing a Dialog based app which has a form for user input and is supposed to be always available while the program is running . At the same time I need to monitor the serial port and all the info that gets in being processed (there are some calcs, checking and responses being sent out).

    I was thinking about using a separated thread for this serial port processing but since I´m really new on that I´m not sure if that´s the case.

    Two questions:

    1) Do you advice me to keep thinking about threads?

    2) In case of YES is it possible to have this separated thread sending information back so that I can show it in my dialog window?

    Thanks in advance.

    Ricardo

  2. #2
    Join Date
    Nov 2000
    Location
    Munich, Germany
    Posts
    161
    Both questions should be answered with "YES".
    Put the serial stuff into a thread which reads from the serial port.
    If something is received from the serial port, you could for example send it to you application with ::SendMessage. (Other solutions are also possible).
    Writing should also be done from the serial thread - don't try to do it from your dialog!!
    Always keep in mind that you now have concurrency. So all your serial thread functions should be packed into a critical section, so that your dialog does not do nasty things while processing data.
    The other way around is not that critical if you follow my recommendation with ::SendMessage.
    Summary: Serial Thread waits for Serial Events and a User Event.
    Dialog sets User Event thus awakening the Serial Thread if something needs to be written by I/O.
    If something is read from I/O the corrsponding driver wakes up the thread itself and the thread then sends the data when complete to your dialog.

  3. #3
    Join Date
    Jul 2002
    Posts
    30

    Thumbs up

    Thanks alot ReorX. That´s exactly what I had on mind (allthough I´ll have do some research from now on to implement it...no problem!!!).

    Anymore tips from experts will be very welcomed.

    Ricardo

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured