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++ Widgets - General questions or Mixed problems » UI window threading problem
UI window threading problem [message #39790] Sun, 28 April 2013 22:28 Go to next message
crydev is currently offline  crydev
Messages: 151
Registered: October 2012
Location: Netherlands
Experienced Member
Hello,

I ran into a problem that I initially fixed, but I'm not convinced that there isn't a better way of solving it. My problem is as following.

I have a main window that is capable of opening another window that runs non-modal above the main window, meaning the main window is not clickable nor focusable while the opened window is still opened. The non-modal window enables the user to select parameters for a memory scan, and by clicking OK the memory scan has to be started. The problem I ran into in the first place was that I had to be able to make the non-modal window access a function in the main window. That isn't too hard to fix, but the next problem is, that the non-modal window keeps on top, non-responsive, until the memory scan that is started is finished. My fix to that problem was creating a new thread that started the memory scan, in order to keep any possible piece of UI responsive. Downside: I had many exceptions that were very hard to find, due to the threading between the UI parts.

Now that I all fixed it, I wonder: isn't there a better solution to achieve the non-modal window to be closed, without the need of a thread?

Thanks in advance!

crydev
Re: UI window threading problem [message #39791 is a reply to message #39790] Mon, 29 April 2013 02:03 Go to previous messageGo to next message
Sender Ghost is currently offline  Sender Ghost
Messages: 299
Registered: November 2008
Experienced Member
Hello, Crydev.
crydev wrote on Sun, 28 April 2013 22:28

Now that I all fixed it, I wonder: isn't there a better solution to achieve the non-modal window to be closed, without the need of a thread?

The simple answer is using of PostCallback before closing non-modal window:
void DoingScan()
{
	// Doing some scanning
	Sleep(1000);
}

void Window::OnOK()
{
	PostCallback(callback(DoingScan));
	Close();
}

But after the reconstruction of what you did, I came to the following solution:
Toggle Spoiler

Where you have access to the contents of the non-modal window after closing it, while run the scanning process on the right exit code.

[Updated on: Mon, 29 April 2013 12:50]

Report message to a moderator

Re: UI window threading problem [message #39794 is a reply to message #39791] Mon, 29 April 2013 10:53 Go to previous messageGo to next message
crydev is currently offline  crydev
Messages: 151
Registered: October 2012
Location: Netherlands
Experienced Member
Thanks a lot Sender Ghost! I used the solution you gave and it works very well. It is even less error prone now. Although I still had to start the scan on another thread to keep the UI responsive, but that thread could be started from the main window, which is perfect. Smile
Re: UI window threading problem [message #39795 is a reply to message #39794] Mon, 29 April 2013 12:52 Go to previous message
Sender Ghost is currently offline  Sender Ghost
Messages: 299
Registered: November 2008
Experienced Member
Actually, there are more solutions, like using ProcessEvents between iterations of your algorithm(s) or even using "Alternative Multithreading" by Pavel Ostapenko.
Previous Topic: Scrolling ArrayCtrl with Ctrls
Next Topic: How to disable mouse cursor application wide ??
Goto Forum:
  


Current Time: Thu May 28 01:23:53 CEST 2020

Total time taken to generate the page: 0.01402 seconds