How would I use SuspendThread and ResumeThread?

Posts 1–5 of 5 · Page 1 of 1
How would I use SuspendThread and ResumeThread?
I've been reading up on google and such, but I haven't found anything related to what I'm looking for. MSDN even said that SuspendThread and ResumeThread has been deprecated, so if there's a better alternative, please inform me.

I'm using the following snippet to create a thread in main.cpp:
Code:
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)&AutoAttack, hWnd, 0, 0);
AutoAttack is declared in bot.cpp. What I'm trying to do is make it so that an autobuff thread will suspend the thread if it's active, send the buff key, then allow the attack thread to resume. A simple example or push in the right direction would be greatly appreciated.
Just to be clear - you're running 2 threads say A & B, and when 'A' gets some kind of event, it should pause 'B', do it's thing and then restart/continue B?

Easiest way is probably instead of a thread to actually put the B(autoattack) in a timer callback with a very short interval. Then when your event A happens (autobuff thingie), simply pause the timer.

Another possible way would be to use a mutex/waitforsingleobject combination where the primary thread locks the mutex every time the event happens (infinite wait) and secondary thread in each cycle tries to lock the mutex (0 wait) and release it right away, allowing it to run only when the primary thread isn't doing it's thing and already has the mutex locked.
That's exactly what I'm doing, and I'll test out both suggestions later on when I get a chance to. Thanks for the input though
Shouldn't it be
Code:
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)AutoAttack, hWnd, 0, 0);
Thats how I always use it(without a & sign)
I don't think it matters, and I've figured it out already. Thanks for the suggestions guys, but I ended up using SuspendThread() and ResumeThread() in the end.
Posts 1–5 of 5 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us