Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » "DoEvents" or "wxSafeYield" equivalent in Upp++
"DoEvents" or "wxSafeYield" equivalent in Upp++ [message #17844] Sun, 31 August 2008 02:09 Go to next message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Hello all

I would like to use some kind of "poor man" multithreading for long "for" loops. Like:
for (int i = 0; i < MANY_LOOPS; ++i) {
  ThingsToDo();
  DoEvents();
}

where DoEvents() lets some kind of "cooperative multitasking" by:
- disabling the user input to all program windows
- asking the Upp++ main loop to handle the pending messages in the windowing system
- re-enabling it again afterwards

Disabling user input would avoid unwanted reentrance of code.

In this moment this will be enough for me and much easier to handle than real multitasking with the gui.

Best regards


Best regards
Iñaki
Re: "DoEvents" or "wxSafeYield" equivalent in Upp++ [message #17845 is a reply to message #17844] Sun, 31 August 2008 09:17 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
You should be able to do this using:

static  Vector<Ctrl *> Ctrl::GetTopCtrls();
Vector< Ptr<Ctrl> > DisableCtrls(const Vector<Ctrl *>& ctrl, Ctrl *exclude = NULL);
static  void Ctrl::ProcessEvents();
void EnableCtrls(const Vector< Ptr<Ctrl> >& ctrl);


Mirek
Re: "DoEvents" or "wxSafeYield" equivalent in Upp++ [message #17860 is a reply to message #17845] Sun, 31 August 2008 19:53 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3357
Registered: August 2008
Senior Veteran
Hello luzr

I have tried this, but it blocks all until the loop ends.
for (int i = 0; i < 100; ++i) {
	Sleep(500);
	Vector<Ctrl *> topCtrls = Ctrl::GetTopCtrls();
	Vector< Ptr<Ctrl> > ctrls = DisableCtrls(topCtrls);
	Ctrl::ProcessEvents();
	EnableCtrls(ctrls);
}


But this simply works perfect. (taking care of avoiding the user to run this code while it is still running).
for (int i = 0; i < 100; ++i) {
	Sleep(500);
	Ctrl::ProcessEvents();
}


Thank you!
Koldo


Best regards
Iñaki
Re: "DoEvents" or "wxSafeYield" equivalent in Upp++ [message #17863 is a reply to message #17860] Sun, 31 August 2008 20:33 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
koldo wrote on Sun, 31 August 2008 13:53

Hello luzr

I have tried this, but it blocks all until the loop ends.
for (int i = 0; i < 100; ++i) {
	Sleep(500);
	Vector<Ctrl *> topCtrls = Ctrl::GetTopCtrls();
	Vector< Ptr<Ctrl> > ctrls = DisableCtrls(topCtrls);
	Ctrl::ProcessEvents();
	EnableCtrls(ctrls);
}


But this simply works perfect. (taking care of avoiding the user to run this code while it is still running).
for (int i = 0; i < 100; ++i) {
	Sleep(500);
	Ctrl::ProcessEvents();
}


Thank you!
Koldo


I thought that "block all" was the purpose of disabling Smile

Note that there is parameter "exclude" in DisableCtrls. Usually, you want to leave something enabled to process cancel messages, right? Smile

Mirek
Previous Topic: selected text in other application
Next Topic: U++ suggestions
Goto Forum:
  


Current Time: Thu Apr 25 00:45:27 CEST 2024

Total time taken to generate the page: 0.04315 seconds