Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8891049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:38:24+00:00 2026-06-14T22:38:24+00:00

I wanted to call function every 5 minutes I tried AutoFunction(){ cout << Auto

  • 0

I wanted to call function every 5 minutes
I tried

AutoFunction(){
    cout << "Auto Notice" << endl;
    Sleep(60000*5);
}

while(1){

    if(current->tm_hour == StartHour && current->tm_min == StartMinut && current->tm_sec == StartSec){
        CallStart();
    }

    AutoFunction();
    Sleep(1000);
}

I want refresh the while every 1 second and at the same time call AutoFunction(); every 5 minutes, but without waiting the Sleep in AutoFunction

because I have to refresh the while(1) every 1 sec to check time to start another function

I thought to do it like

while(1){

    if(current->tm_hour == StartHour && current->tm_min == StartMinut && current->tm_sec == StartSec){
        CallStart();
    }

    Sleep(1000);
}
while(1){

    AutoFunction();
    Sleep(60000*5);
}

but I don’t think so both will working together

Thank You

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T22:38:26+00:00Added an answer on June 14, 2026 at 10:38 pm

    For those of us who are unfamiliar with threads and Boost libraries, this can be done with a single while loop:

    void AutoFunction(){
        cout << "Auto Notice" << endl;
    }
    
    //desired number of seconds between calls to AutoFunction
    int time_between_AutoFunction_calls = 5*60;
    
    int time_of_last_AutoFunction_call = curTime() - time_between_AutoFunction_calls;
    
    while(1){
        if (should_call_CallStart){
            CallStart();
        }
    
        //has enough time elapsed that we should call AutoFunction?
        if (curTime() - time_of_last_AutoFunction_call >= time_between_AutoFunction_calls){
            time_of_last_AutoFunction_call = curTime();
            AutoFunction();
        }
        Sleep(1000);
    }
    

    in this code, curTime is a function I made up that returns the Unix Timestamp as an int. Substitute in whatever is appropriate from your time library of choice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to call Test1() Method Within WaitAndCallFunc() Function. Code: typedef void (*func)(); void
I wanted to call a function when all required images are loaded. The number
I have this class file call SMSHelper.cs First I just wanted to know is
I was trying to make a constructor function and within it, i had/wanted to
Given : script with multiple functions in it (see below) Wanted : call a
So I wrote some numerical code in C but wanted to call it from
I have a background service running and inside this I wanted to call a
Possible Duplicate: how to apply a function to every row of a matrix (or
I use redirect() (from uri helper) in every function who need to load the
I wanted to add a loading class to the body element on every ajax

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.