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++ MT-multithreading and servers » Code before Thread.Run() nor executed
Re: Code before Thread.Run() nor executed [message #48671 is a reply to message #48669] Tue, 15 August 2017 18:45 Go to previous messageGo to previous message
Oblivion is currently offline  Oblivion
Messages: 1092
Registered: August 2007
Senior Contributor
As I suspected, you are calling GUI elements/methods from a worker thread directly. You need to use PostCallback, and make sure the thread terminates.
Here you go:

TestLayout::TestLayout()
{
	CtrlLayout(*this);
	button1 << THISBACK(OnCLickButton);
}

void TestLayout::OnCLickButton()
{
	WhenThreadStart();
}


TestLayout2::TestLayout2()
{
	CtrlLayout(*this);
	progress.Set(0, 1);
}

TestWindow::TestWindow()
{
	SetRect(0, 0, Zx(400), Zy(200));
	Add(testLayout);
	Add(testLayout2);
	testLayout.Show(true);
	testLayout2.Show(false);
	testLayout.button1.WhenAction = THISBACK(StartProgress); // button1's WhenAction callback was not defined.
}

void TestWindow::StartProgress()
{
	testLayout.Show(false);
	testLayout2.Show(true);
	testLayout2.progress.Set(0, 10); 
	Thread().Run(THISBACK(Progress));
}

void TestWindow::Progress()
{
	// This thread code could be written in a much better way, but I'm simply giving you the idea :). 
	for(int i = 0; i < 10; i++)
	{
		if(Thread::IsShutdownThreads())
			break;
		Sleep(1000);
		PostCallback([=]{ 
		    // Never directly call GUI elements. If wou want to do fancy GUI stuff with
		    // threads, use PostCallback. 
			testLayout2.progress++;

		});
	}
	PostCallback([=]{	
			// Let us roll-back;
			testLayout2.Hide();
			testLayout.Show();
	});

}

TestWindow::~TestWindow()
{
	// Make sure that running threads terminate.
	if(Thread::GetCount())
		Thread::ShutdownThreads();
}


Best regards,
Oblivion


[Updated on: Wed, 16 August 2017 07:47]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How to use TLS over SMTP
Next Topic: HttpRequest ignores server errors
Goto Forum:
  


Current Time: Sat Apr 20 09:56:18 CEST 2024

Total time taken to generate the page: 0.01550 seconds