Hey, I'm trying to use a timer but not to be the main thread because I want the program I'm detouring to go on running and do not have to wait untill Sleep period ends and then continue, so here is my source code.. everything works fine but it's just that my Timer affects the main thread and everything stops untill sleep period ends, there u go:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
int __fastcall MyWeaponPutOff(void *Item, void *edx, int Player)
{
int Time = 0;
for(;;)
{
if( Time >= Timer )
{
if ( IsNormal(Player) ) // if player online it turns to original function
return WeaponPutOff(Item,Player);
Time = 0;
}
Sleep(1000);
Time++;
}
return 0;
}
then can you please show me how to make sleep without letting the main thread affected?
I even tried to make sub functions but I still don't get it...
If someone could apply to my code how to make Sleep without affecting the main thread would be great..
I literally cant sleep at night because of this one lol :D
yep been trying but I get tons of errors everytime I try to pass variables into it, it does not want to accept it... so if someone knows how could u show me on my example please it would be more understandable for me,, thanks
multithreading is a heavy subject, basically you can think of making a new thread like making a new main, then the new threads runs on different code then your original main. If there is sleep in the code that the main runs on, then main will sleep. But if the sleep is in another threads code, then that thread will sleep. I personally dont understand why you need multithreading.
what you probably want to do is not use sleep at all. But make a function that will return after 1000 seconds, and meanwhile it will try to do some work. for that you need some sort of class called JobPool that you give it jobs to do. when you activate it, it will perfore a job and check what time it is, whether its time to stop doing jobs or not. then take another job, do job.run(), then see what time it is again, all that in a loop, that looks something like this.