Hey Guys i need help how i make a loop timer what run all 10 min a command
like
printf("Test")
after 10 min he send self and this the full time.
thx
like
printf("Test")
after 10 min he send self and this the full time.
thx
while(true) {
printf("Test");
Sleep(600000);
}
If the compiler supports UDLs and the time literals:Quote:
Code:Sleep(600000);
#include <chrono> #include <thread> // ... using namespace std::literals::chrono_literals; std::this_thread::sleep_for (10min);
#include <chrono>
#include <thread>
#include <initializer_list>
// ...
std::this_thread::sleep_for (std::chrono::minutes {10});
Nur rein aus interesse: Gibts einen bestimmten Grund, warum du die Minuten als initializer list angibst? An der Stelle würde es eine einfache Klammer doch genau so tun.Quote:
If the compiler supports UDLs and the time literals:
If not:Code:#include <chrono> #include <thread> // ... using namespace std::literals::chrono_literals; std::this_thread::sleep_for (10min);
That doesn't require windows.Code:#include <chrono> #include <thread> #include <initializer_list> // ... std::this_thread::sleep_for (std::chrono::minutes {10});
Das ist richtig. Aber so wird das nicht mit einem "gewöhnlichen" Funktionsaufruf verwechselt, noch kommt der Compiler auf die Idee, das als Funktionsdeklaration auszugeben (hier natürlich nicht). Wenn nicht der Aufruf eines expliziten Konstruktors das Ziel ist oder Mehrdeutigkeiten entstehen würden, kann der Typ auch weggelassen werden, wenn geschweifte Klammern verwendet werden. Und wenn man das deshalb immer so macht...Quote:
Nur rein aus interesse: Gibts einen bestimmten Grund, warum du die Minuten als initializer list angibst? An der Stelle würde es eine einfache Klammer doch genau so tun.
#include <iostream>
#include <Windows.h>
#include <time.h>
void wait(long seconds)
{
seconds = seconds * 1000;
Sleep(seconds);
}
int main(void)
{
std::cout << "..." << std::endl;
wait(5);
return 0;
}
Zuerst sei mal gesagt das der TE dich nicht versteht weil er deine Sprache (offensichtlich) nicht spricht.Quote:
Ich bin selber noch ein noob in C++ ^^
Also ich kenne mich auch noch net besonders damit aus aber ich würde das ganze so machen:
Und da du ja 10 Minuten haben möchtest würde ich das ganze auch in Minuten takt sozusagen angeben.Code:#include <iostream> #include <Windows.h> #include <time.h> void wait(long seconds) { seconds = seconds * 1000; Sleep(seconds); } int main(void) { std::cout << "..." << std::endl; wait(5); return 0; }
Also hinter das seconds = seconds * 1000 einfach ein * 60 ergänzen.
seconds = seconds * 1000 * 60;
[Only registered and activated users can see links. Click Here To Register...]Quote:
Note that with Sleep()/nanosleep(), the OS only guarantees that the process suspension will last for at least as long as you specify. The execution of other processes can always delay resumption of your process.
DWORD starttimer = GetTickCount();
// Insert loop ?
if( GetTickCount() - starttimer >= 60000 ) // 10 min have passed
{
// do something
starttimer = GetTickCount(); // restart timer
}
fuck the winapi.Quote:
Code:DWORD starttimer = GetTickCount(); // Insert loop ? if( GetTickCount() - starttimer >= 60000 ) // 10 min have passed { // do something starttimer = GetTickCount(); // restart timer }
#ifndef TIMER_H
#define TIMER_H
#include <chrono>
template <typename T>
class Timer
{
private:
std::chrono::time_point<std::chrono::high_resolution_clock> tStart;
public:
Timer()
{
tStart = std::chrono::high_resolution_clock::now();
}
__int64 diff()
{
return std::chrono::duration_cast<T>(std::chrono::high_resolution_clock::now() - tStart).count();
}
void reset()
{
tStart = std::chrono::high_resolution_clock::now();
}
};
#endif
Timer<std::chrono::minutes> timer;
if( timer.diff() > 10 ) { .. }