Click to See Complete Forum and Search --> : is a Thread suitable for this app?


javo
March 24th, 2004, 06:20 AM
Hello,

I was wondering if to use threads could be the good solution to the following problem.

I would like to developt a dialog based application that sends Data (A canbus message similar to RS232 but instead to a Canbus Network) when I push a bottom. I want also to send this message periodically (each 100 ms) when a box is checked. I have my application running OK with the push buttom but I want to add the periodic sending of Canbus messages feature.

I have read about Threads and I would like to ask you if a worker thread that do Sleep(100) and then post a message to the GUI in order to the GUI execute the same function as when the buttom is pushed could be a good solution or maybe is there something more suitable?. I am very new to Visual c++ so I don't know all the possibilies that I could use for solving this at the moment.

Thanks a lot and best regards,

Javo

Andreas Masur
March 24th, 2004, 06:23 AM
[Moved thread]

kochhar
March 24th, 2004, 09:12 AM
Yes, using a thread seems the proper thing to do in this case. You might also just have the thread send the data directly rather than posting a messge to the dialog etc.

javo
March 24th, 2004, 09:40 AM
In my case I have the SendMessage function in the MyDlg.cpp of the application, is it possible to call a function of this first thread from a second Thread created also in this first Thread? I thought that I should use the sending messages instead??.

I have read about SetTimer, etc would it be better to use timers instead of threaths?? (I would like to call each 100 ms a function if a check box is checked and nothing if it's not checked).

Thanks a lot and best regards,

Javo

Sam Hobbs
March 24th, 2004, 06:38 PM
Originally posted by javo
when I push a bottom
Originally posted by javo
when a box is checked
Originally posted by javo
the GUI execute the same function as when the buttom is pushedThis is confusing for me. The button is (part of) the GUI.

Regardlous, the question of whether to use threads depends essentially on whether there is an asychronous event that needs to be processed. If sending the data can be done sequentially without waiting for something, and if sending the data will not require a lot of time, then there is no need for a thread. A timer would be used to send the data periodically as needed.

underscore
March 25th, 2004, 11:11 AM
you can simply set timer message to your dialog and when you receive your OnTimer you can send the message, this will be easy to implement (winodws as serious problem with multi threading). Your dialog will stay responsive while the timer is running in the background by the OS..