Panel Issues
-
I am having some weird panel issues. In my program I have multiple panels of different contents. For example there is a welcome screen, the user clicks next and the welcome screen is not visible and the next screen is.When the screens are changed with the next button they work fine. Here is where the problem is... However if I want to change them from a seperate thread, the panel is visible but the contents of the panel are not. I am calling the same function to change the panels' visiblity (and the contents have all been set to visible). I have made sure that all labels were changed using the invokerequired/settextcallback stuff. What am I forgetting?
-
I am having some weird panel issues. In my program I have multiple panels of different contents. For example there is a welcome screen, the user clicks next and the welcome screen is not visible and the next screen is.When the screens are changed with the next button they work fine. Here is where the problem is... However if I want to change them from a seperate thread, the panel is visible but the contents of the panel are not. I am calling the same function to change the panels' visiblity (and the contents have all been set to visible). I have made sure that all labels were changed using the invokerequired/settextcallback stuff. What am I forgetting?
Hi, Threads (all kinds of them, including ThreadPool threads, and BackgroundWorkers) other than the thread that created a Control (BTW: a Form is also a Control), should not access that Control, except for the very few members explicitly allowed, including InvokeRequired and Invoke. Before .NET 2.0 the app may behave badly, the GUI may freeze, anything can go wrong if you violate the rule. Since 2.0 you get an InvalidOperationException by default; you can disable that by setting Control.CheckForIllegalCrossThreadCalls false, but that is a very bad idea, and it brings you back in the previous situation. Since most if not all Controls are somehow related (they are on a Form, one Form owns another Form, etc), the natural consequence is all Controls get created and accessed exclusively by a single thread, typically your initial or main thread, often also called the "GUI thread". There are lots of examples on InvokeRequired/Invoke available everywhere; a rather advanced article on the subject is here. :)
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
-
I am having some weird panel issues. In my program I have multiple panels of different contents. For example there is a welcome screen, the user clicks next and the welcome screen is not visible and the next screen is.When the screens are changed with the next button they work fine. Here is where the problem is... However if I want to change them from a seperate thread, the panel is visible but the contents of the panel are not. I am calling the same function to change the panels' visiblity (and the contents have all been set to visible). I have made sure that all labels were changed using the invokerequired/settextcallback stuff. What am I forgetting?
OK so I found something. Though I set the text values in a thread safe manner apparently I don't set the panel's visible property in a thread safe manner. Any suggestions on how to do that? Please don't say a timer, because I have had such bad luck with the form timers in this program. I just can't get them to tick, but that is another issue. Edited to add: Weird I didn't see that last reply until after I posted this. I will check out the link. Thanks
-
OK so I found something. Though I set the text values in a thread safe manner apparently I don't set the panel's visible property in a thread safe manner. Any suggestions on how to do that? Please don't say a timer, because I have had such bad luck with the form timers in this program. I just can't get them to tick, but that is another issue. Edited to add: Weird I didn't see that last reply until after I posted this. I will check out the link. Thanks
OKay I got it.
static void SetVisible(Control ctrl, bool visible) { if (ctrl.InvokeRequired) { object\[\] params\_list = new object\[\] { ctrl, visible }; ctrl.Invoke(new SetVisibleDelegate(SetVisible), params\_list); } else { ctrl.Visible = visible; } }