Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,668 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,148 people online right now. Registration is fast and FREE... Join Now!




Timer to call a function.

 
Reply to this topicStart new topic

Timer to call a function.

mickoo
post 18 Jul, 2007 - 08:12 AM
Post #1


New D.I.C Head

*
Joined: 18 Jul, 2007
Posts: 4


My Contributions


Hi i am using this codeto display an on-screen-display for a STB

CODE

void mcx_change_market_message() {

        // remove any message first
        mcx_remove_message(3);

        // display OSD text
        mcx_display_message( 0xFF, LDBf(Ldb_osd_msg_66), 3 );

}


the function mcx_display_message does the required action. But i want to display it only for 10 seconds

the functions mcx_remove_message(3) removes this message hence if i call this function after 10 seconds it will do the required job.

But i dont want to use sleep as it will block all other processes that are running on background. So any other suggestion of using a timer which starts when mcx_display_message starts and then waits for ten seconds then call mcx_remove_message

User is offlineProfile CardPM

Go to the top of the page

PennyBoki
post 18 Jul, 2007 - 09:03 AM
Post #2


system("revolution");

Group Icon
Joined: 11 Dec, 2006
Posts: 2,009



Thanked 5 times

Dream Kudos: 500

Expert In: Java,C++,C

My Contributions


Hi have you tried this with wait(). I haven't done this before, but I'm sure that there must be a wait function see here

http://www.cplusplus.com/reference/clibrary/ctime/clock.html

This post has been edited by PennyBoki: 18 Jul, 2007 - 09:05 AM
User is offlineProfile CardPM

Go to the top of the page

1lacca
post 18 Jul, 2007 - 11:55 AM
Post #3


code.rascal

Group Icon
Joined: 11 Aug, 2005
Posts: 3,822



Thanked 11 times
My Contributions


- the link above shows a wait function that would actually block, so I think you don't want to do this, but that is an option.
- launch a thread, that would do the same, but this way the original thread could continue, and your program is not blocked
- use some os dependent thing, on Linux it is called setitimer (you can register a callback function that is executed at a given time), on Windows I don't know, but google should find it...

This post has been edited by 1lacca: 18 Jul, 2007 - 11:56 AM
User is offlineProfile CardPM

Go to the top of the page

mickoo
post 18 Jul, 2007 - 01:15 PM
Post #4


New D.I.C Head

*
Joined: 18 Jul, 2007
Posts: 4


My Contributions


QUOTE(1lacca @ 18 Jul, 2007 - 12:55 PM) *

- the link above shows a wait function that would actually block, so I think you don't want to do this, but that is an option.
- launch a thread, that would do the same, but this way the original thread could continue, and your program is not blocked
- use some os dependent thing, on Linux it is called setitimer (you can register a callback function that is executed at a given time), on Windows I don't know, but google should find it...



Thanks I was able to solve it. Where can i learn more about threads...
User is offlineProfile CardPM

Go to the top of the page

1lacca
post 18 Jul, 2007 - 11:04 PM
Post #5


code.rascal

Group Icon
Joined: 11 Aug, 2005
Posts: 3,822



Thanked 11 times
My Contributions


Threads are unfortunately OS dependent thing and are not defiend by the C++ language itself.
So if you want to learn about them in general, or if you are looking for a howto on a specific platform, then a well crafted google search would do the trick.
If you want to create a cross platform application that takes advantage of threading, then find a library that is available on the platforms you target. C++ Portable Types Library might be just that, but I haven't tried it myself, however other members might have some recommendations.
User is offlineProfile CardPM

Go to the top of the page

Skinner
post 20 Jul, 2007 - 05:32 AM
Post #6


New D.I.C Head

*
Joined: 13 Aug, 2006
Posts: 20


My Contributions


QUOTE(mickoo @ 18 Jul, 2007 - 09:12 AM) *

Hi i am using this codeto display an on-screen-display for a STB

CODE

void mcx_change_market_message() {

        // remove any message first
        mcx_remove_message(3);

        // display OSD text
        mcx_display_message( 0xFF, LDBf(Ldb_osd_msg_66), 3 );

}


the function mcx_display_message does the required action. But i want to display it only for 10 seconds

the functions mcx_remove_message(3) removes this message hence if i call this function after 10 seconds it will do the required job.

But i dont want to use sleep as it will block all other processes that are running on background. So any other suggestion of using a timer which starts when mcx_display_message starts and then waits for ten seconds then call mcx_remove_message



Can't you just use a TTimer component which starts when the message is displayed and when finished invokes the required hide method?
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/23/08 05:54AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month