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 |
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
Github page: https://github.com/ismail-yilmaz
upp-components: https://github.com/ismail-yilmaz/upp-components
Bobcat the terminal emulator: https://github.com/ismail-yilmaz/Bobcat
[Updated on: Wed, 16 August 2017 07:47] Report message to a moderator
|
|
|
|
|
Code before Thread.Run() nor executed
By: rafiwui on Mon, 14 August 2017 13:23
|
|
|
Re: Code before Thread.Run() nor executed
By: Oblivion on Tue, 15 August 2017 08:05
|
|
|
Re: Code before Thread.Run() nor executed
By: rafiwui on Tue, 15 August 2017 09:07
|
|
|
Re: Code before Thread.Run() nor executed
By: Oblivion on Tue, 15 August 2017 18:45
|
|
|
Re: Code before Thread.Run() nor executed
By: rafiwui on Wed, 16 August 2017 09:43
|
|
|
Re: Code before Thread.Run() nor executed
By: mirek on Sat, 26 August 2017 13:16
|
|
|
Re: Code before Thread.Run() nor executed
By: rafiwui on Mon, 28 August 2017 08:38
|
|
|
Re: Code before Thread.Run() nor executed
By: mirek on Mon, 28 August 2017 09:27
|
|
|
Re: Code before Thread.Run() nor executed
By: rafiwui on Mon, 28 August 2017 09:39
|
|
|
Re: Code before Thread.Run() nor executed
By: rafiwui on Mon, 28 August 2017 10:51
|
|
|
Re: Code before Thread.Run() nor executed
By: mirek on Tue, 29 August 2017 17:20
|
|
|
Re: Code before Thread.Run() nor executed
By: rafiwui on Tue, 29 August 2017 18:21
|
|
|
Re: Code before Thread.Run() nor executed
By: mirek on Tue, 29 August 2017 20:26
|
|
|
Re: Code before Thread.Run() nor executed
By: rafiwui on Tue, 29 August 2017 20:30
|
|
|
Re: Code before Thread.Run() nor executed
By: mirek on Sat, 26 August 2017 13:16
|
Goto Forum:
Current Time: Sat Apr 20 09:56:18 CEST 2024
Total time taken to generate the page: 0.01550 seconds
|