Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

How to create...

Custom Title Activated
Loyal Member
Joined
Mar 26, 2012
Messages
1,465
Reaction score
130
How do I create a continuous loop with a pause within it and have it continue to the next bit of code when it reaches the end the first time. C++ 2017 Visual Studio. Basically I want my program to look for running processes based on the titles and close if found while my program continues to run. Example:
Code:
LOOP{
if(statement){
/do something
}
else if(statement){
do something
//jump to next bit of code outside of loop
//timeout for loop
}
}
//This is next bit of code that does something while loop is running
CODE
CODE
CODE

Thank you.
 

nck

Newbie Spellweaver
Joined
Nov 6, 2018
Messages
6
Reaction score
7
Do you mean the ?
 
Junior Spellweaver
Joined
Oct 27, 2008
Messages
165
Reaction score
89
C/C++ programming basics - Control Structures:



If you want to run code in parallel you should use threads:
PHP:
#include <thread>
#include <condition_variable>

class CEvent
{
	bool m_bReady = false;
	std::mutex m_mutex;
	std::condition_variable m_event;
public:
	void WaitToFinish(void)
	{
		std::unique_lock<std::mutex> mlock(m_mutex);
		m_event.wait(mlock, [this] {return this->m_bReady; });
            m_bReady =  false;
	}

	void SignalAsFinished(void)
	{
		std::lock_guard<std::mutex> guard(m_mutex);
		m_bReady = true;
		m_event.notify_one();
	}
};


class MyAppClass
{
	bool m_bRunning = false;
	std::thread m_thread;
public:
	void Startup(void)
	{
		CEvent event;
		m_thread = std::thread(&MyAppClass::NewThread, this, std::ref(event));
		event.WaitToFinish();

		//This is next bit of code that does something while loop is running
		// CODE
		// CODE
		// CODE
	
	}

	void Shutdown(void)
	{
		m_bRunning = false;
		m_thread.join();
	}
private:
	void NewThread(CEvent& event)
	{
		m_bRunning = true;
		event.SignalAsFinished();

		while (m_bRunning)
		{
			if (statement) {
				// do something
			}
			else if (statement) {
				//do something
					//jump to next bit of code outside of loop
					//timeout for loop
			}
		}

		m_bRunning = false;
	}
};

For more details read about threads locks, mutexes and semaphors:


It is also usefull to read about IPC(Interprocess communication), it is usefull for communication between threads and processes
 
Last edited:
Back
Top