Calling custom wxDialog's "ShowModal()" from secondary thread Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
ibrahim
Earned some good credits
Earned some good credits
Posts: 124
Joined: Mon Mar 14, 2022 8:02 am

Calling custom wxDialog's "ShowModal()" from secondary thread

Post by ibrahim »

I have two threads , on thread exists so that the UI doesnt get blocked when executing events , and another thread exists to execute the events.

I am using wxWidgets with C++ /CLI and I am using a .NET thread. 8)

Before you say "YoU sHoUlDn'T cAlL gUI mEtHoDs FrOm A sEcOnDaRy ThReAd" , the wxMessageDialog's "ShowModal()" works in a seperate thread (Even though the thread is a .NET thread), which means my Custom Message Dialog should work too. :)


Also please don't give me complicated wxThread stuff and non-working code, if the wxMessageDialog works without me having to create a wxThread class then my dialog also shouldn't have to create its own wxThread class. :evil:


I just want to know exactly how the wxMessageDialog's "ShowModal()" can be called from a secondary thread.


The custom dialog's widgets do work in the thread though, but the debug alert thing shows up when using it. And when using wxMessageDialog in the thread, the debug alert message doesn't show up

I've tried surrounding the "ShowModal()" call with wxMutexGuiEnter(); and wxMutexGuiLeave(); even that didnt work
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Calling custom wxDialog's "ShowModal()" from secondary thread

Post by ONEEYEMAN »

Hi,
Please do not cross-post on different forums - it makes helping you harder.
Please check the SO as I just replied there .
Thank you.
ibrahim
Earned some good credits
Earned some good credits
Posts: 124
Joined: Mon Mar 14, 2022 8:02 am

Re: Calling custom wxDialog's "ShowModal()" from secondary thread

Post by ibrahim »

Are You "Igor"
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Calling custom wxDialog's "ShowModal()" from secondary thread

Post by ONEEYEMAN »

Hi,
Yes, and?

Thank you.
ibrahim
Earned some good credits
Earned some good credits
Posts: 124
Joined: Mon Mar 14, 2022 8:02 am

Re: Calling custom wxDialog's "ShowModal()" from secondary thread

Post by ibrahim »

Don't be mad

I need threads, for a generic progress dialog, while im executing my function I need to update the progress dialog , but the progress dialog is blocked since i'm executing a function, thats why I need threads.

I can't find any alternative to this
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Calling custom wxDialog's "ShowModal()" from secondary thread

Post by ONEEYEMAN »

Hi,
No you don't.
wx{Generic}ProgressDialog is using thread internally.
All you do is to call update from your code.

Check dialogs sample/documentation for more details.

Thank you.
ibrahim
Earned some good credits
Earned some good credits
Posts: 124
Joined: Mon Mar 14, 2022 8:02 am

Re: Calling custom wxDialog's "ShowModal()" from secondary thread

Post by ibrahim »

Really ?!! last time I used it , it was blocked
ibrahim
Earned some good credits
Earned some good credits
Posts: 124
Joined: Mon Mar 14, 2022 8:02 am

Re: Calling custom wxDialog's "ShowModal()" from secondary thread

Post by ibrahim »

Okay , wxgenericProgressDialog is definitely not using threading.

I compiled this with wxWidgets 3.1.5

Here is my test to see if it is has internal threading :

As well as having no threading, the progress dialog slows down the entire program
Generic_Progress_Dialog_Test.zip
(3.66 KiB) Downloaded 26 times
Every 1.5 seconds , I am updating the dialog.

When using threads the dialog seems to be working and everything seems fine.
Making the progress dialog smooth also doesnt work. I'm confused since your saying its supposed to work but its clearly not

When I move the dialog around, it takes at least a second for the dialog to move to its new position. Is this a bug in 3.1.5 that is fixed in 3.1.6 ?? vcpkg only gives me version 3.1.5 of wxWidgets.

Can you give a line number of where the wxGenericProgressDialog is tested in the samples. there are thousands of lines.


Edit :

Also I was thinking that Instead of having threads that update the GUI, I will be sending events to the main thread from the secondary threads that update the GUI. I could also use CallAfter() and call a method that would show my custom dialog.

But In C++ /CLI when I declare events I get a inner C++ /CLI exception :

System.TypeInitializationException: 'The type initializer for '<Module>' threw an exception.'

But In C++ everything works fine.

Edit 2 :

Another Idea I came up with , since progress dialogs have there own internal thread, calling the Update() method on a secondary own thread shouldn't be a problem since its already using an internal thread to so.
ibrahim
Earned some good credits
Earned some good credits
Posts: 124
Joined: Mon Mar 14, 2022 8:02 am

Re: Calling custom wxDialog's "ShowModal()" from secondary thread

Post by ibrahim »

Alright , I have figured out what to do. Instead of calling the GUI methods directory, from my thread I am calling "CallAfter()" to a function that will call the GUI methods from the main thread. That way I'm not running any GUI methods in a thread.
Last edited by ibrahim on Wed May 18, 2022 12:07 pm, edited 1 time in total.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Calling custom wxDialog's "ShowModal()" from secondary thread

Post by ONEEYEMAN »

Hi,
1. Why do you need generic version?
2. Is slowing down the app reproducible in dialogs sample?

Thank you.
ibrahim
Earned some good credits
Earned some good credits
Posts: 124
Joined: Mon Mar 14, 2022 8:02 am

Re: Calling custom wxDialog's "ShowModal()" from secondary thread

Post by ibrahim »

I can't remember why I needed a generic progress dialog. But I did need it.

I will try to reproduce it

BTW can you please read my message above.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Calling custom wxDialog's "ShowModal()" from secondary thread

Post by ONEEYEMAN »

Hi,
1. My question was: why did you need it vs wxProgressDialog. What is the difference between native and general so that you prefer the latter.

2. Yes, I did. And it is a good solution.

3. Please try to reproduce the behavior in the sample. If you can - submit it on wxWidgets issues.

Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Calling custom wxDialog's "ShowModal()" from secondary thread

Post by doublemax »

ibrahim wrote: Wed May 18, 2022 12:03 pm I can't remember why I needed a generic progress dialog. But I did need it.
In your thread from two months ago you wanted to bind an event handler to the Cancel button.
Use the source, Luke!
ibrahim
Earned some good credits
Earned some good credits
Posts: 124
Joined: Mon Mar 14, 2022 8:02 am

Re: Calling custom wxDialog's "ShowModal()" from secondary thread

Post by ibrahim »

Oh Wait yeh now I remember
Post Reply