|
You last visited: Today at 03:28
Advertisement
How i make a Timer for run all 10 min a Command
Discussion on How i make a Timer for run all 10 min a Command within the C/C++ forum part of the Coders Den category.
07/31/2014, 15:21
|
#1
|
elite*gold: 750
Join Date: Jan 2013
Posts: 229
Received Thanks: 368
|
How i make a Timer for run all 10 min a Command
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
|
|
|
07/31/2014, 15:47
|
#2
|
elite*gold: 110
Join Date: Jun 2013
Posts: 599
Received Thanks: 510
|
Code:
while(true) {
printf("Test");
Sleep(600000);
}
you could put that into a thread.
|
|
|
07/31/2014, 17:27
|
#3
|
elite*gold: 0
Join Date: Aug 2012
Posts: 236
Received Thanks: 94
|
Quote:
Originally Posted by Tension
|
If the compiler supports UDLs and the time literals:
Code:
#include <chrono>
#include <thread>
// ...
using namespace std::literals::chrono_literals;
std::this_thread::sleep_for (10min);
If not:
Code:
#include <chrono>
#include <thread>
#include <initializer_list>
// ...
std::this_thread::sleep_for (std::chrono::minutes {10});
That doesn't require windows.
|
|
|
08/08/2014, 11:24
|
#4
|
elite*gold: 0
Join Date: Feb 2008
Posts: 2,754
Received Thanks: 1,748
|
Quote:
Originally Posted by Tasiro
If the compiler supports UDLs and the time literals:
Code:
#include <chrono>
#include <thread>
// ...
using namespace std::literals::chrono_literals;
std::this_thread::sleep_for (10min);
If not:
Code:
#include <chrono>
#include <thread>
#include <initializer_list>
// ...
std::this_thread::sleep_for (std::chrono::minutes {10});
That doesn't require windows.
|
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.
|
|
|
08/08/2014, 22:29
|
#5
|
elite*gold: 0
Join Date: Aug 2012
Posts: 236
Received Thanks: 94
|
Quote:
Originally Posted by Computerfreek
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.
|
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...
|
|
|
08/11/2014, 17:29
|
#6
|
elite*gold: 274
Join Date: Jun 2012
Posts: 4,523
Received Thanks: 434
|
Im a C++ noob too.
So im not sure if it is the best for you but eventually this can help you
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;
}
And if you want 10 Minutes you can form the seconds into minutes.
Behind the seconds = seconds * 1000 just a * 60.
seconds = seconds * 1000 * 60;
Because then you multiple 60 times the 1 Second (= 1 Minute ^.^)
I hope it was a little help for you
|
|
|
08/11/2014, 18:46
|
#7
|
elite*gold: 1091
Join Date: Jun 2007
Posts: 19,836
Received Thanks: 7,180
|
Quote:
Originally Posted by MaBarker
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:
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;
}
Und da du ja 10 Minuten haben möchtest würde ich das ganze auch in Minuten takt sozusagen angeben.
Also hinter das seconds = seconds * 1000 einfach ein * 60 ergänzen.
seconds = seconds * 1000 * 60;
|
Zuerst sei mal gesagt das der TE dich nicht versteht weil er deine Sprache (offensichtlich) nicht spricht.
Dann ist deine Lösung unschön weil sie erstens blockt und zweitens Sleep nicht wirklich genau ist. Achja, und es ist ebenfalls nicht portabel.
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.
|
Wobei das hier vermutlich keine all zu große Rolle spielt.
|
|
|
08/11/2014, 19:39
|
#8
|
elite*gold: 274
Join Date: Jun 2012
Posts: 4,523
Received Thanks: 434
|
Ups mit der Sprache hab ich gefailt sry.
Werds gleich editen.
Und das mit der Sleep Funk. werd ich mir gleich nochmal gründlich durchlesen aber danke dafür
|
|
|
08/13/2014, 01:25
|
#9
|
elite*gold: 750
Join Date: Jan 2013
Posts: 229
Received Thanks: 368
|
My Problem i cant use Sleep this its my problem after i use seelp stop all
|
|
|
08/13/2014, 14:20
|
#10
|
elite*gold: 274
Join Date: Jun 2012
Posts: 4,523
Received Thanks: 434
|
Can you give us the code where you try to use it ?
Eventually you have a little fail
|
|
|
08/15/2014, 11:38
|
#11
|
elite*gold: 150
Join Date: Apr 2007
Posts: 2,394
Received Thanks: 6,644
|
Code:
DWORD starttimer = GetTickCount();
// Insert loop ?
if( GetTickCount() - starttimer >= 60000 ) // 10 min have passed
{
// do something
starttimer = GetTickCount(); // restart timer
}
|
|
|
08/19/2014, 12:22
|
#12
|
elite*gold: 1826
Join Date: Mar 2009
Posts: 4,310
Received Thanks: 6,287
|
Quote:
Originally Posted by wurstbrot123
Code:
DWORD starttimer = GetTickCount();
// Insert loop ?
if( GetTickCount() - starttimer >= 60000 ) // 10 min have passed
{
// do something
starttimer = GetTickCount(); // restart timer
}
|
**** the winapi.
Code:
#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
Code:
Timer<std::chrono::minutes> timer;
if( timer.diff() > 10 ) { .. }
|
|
|
 |
Similar Threads
|
[REQUEST~GUIDE]How to make a Timer
02/12/2010 - CO2 Private Server - 1 Replies
Hei all, i need a guide to make a timer, ive made the start but i want to end it if (DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
{
if (DateTime.Now.Hour == 13 && DateTime.Now.Minute >= 59)
Please someone gimme a guide to do that
|
How can I make this command do the Opposite?
01/30/2010 - CO2 Private Server - 8 Replies
How can I change this command to delete an account in my folder of Users instead of creating?
if (Cmd == "/newacc" && Cmd.Length > 2)
{
if (Cmd.Length == 3)
Database.CreateAccount(Cmd, Cmd, "");
else
Database.CreateAccount(Cmd, Cmd, Cmd);
}
|
[regust] timer in 1565 and help how make ivents start in some time.
11/29/2009 - CO2 Private Server - 4 Replies
Plyz help my thanks
|
Anyone can make Gm command for this server ?
11/16/2009 - Cabal Hacks, Bots, Cheats, Exploits & Macros - 1 Replies
CABAL Online MMoGreat.COM!!!
or tell my be pm how to find this addresses ? and what to do with value ?
|
make OOG bot buff on command
10/12/2008 - Lineage 2 - 3 Replies
hello.
i am curios about something. is it possible to ma make a bot do a special action when hi gets a pm, or gets invited by a specific char ?
example 1: if i invite a bd in party, hi will do fighter dances (dances that i set)
example 2: if i pm a pp, hi will buff me some buffs
any ideas ?
|
All times are GMT +1. The time now is 03:29.
|
|