In Design mode the Load event of user controls get executed. The form's Load event does not get executed. At first this might not appear to be much of an issue in most cases. However, when a background worker thread is started from within the user control load event (that should only be executed at runtime), this can cause issues. I have a larger project where I fire up a background worker thread from within a user control which interacts with the Windows Scheduler. This caused instability in Visual Studio and caused Design mode and rendering of the form UI to fail. It occasionally also could not locate the referenced DLL required by the thread, yet the DLL existed and was found at runtime. The exit condition for my thread would only ever be reached at runtime and would never be reached at design time.
This seems to occur with both standards Windows user controls as well as DevX user controls.
I have attached a small sample project that demonstrates this. I was not able to reproduce the crash issue in the sample project, but from the attached project it is clear to see that the background worker threads get executed and would never reach an exit condition unless explicitly provided (which as I mentioned above in my full project the exit condition would only ever be reached at runtime).
Is this expected behavior? Is there a way to detect Design mode versus runtime mode so as to prevent my worker thread from getting started?
Thanks, Elan
Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.
Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.
Hello Elan,
Thank you for the question. The answer is yes, this behavior is by design. Moreover, it is not related to our controls directly. If you try to use a standard Windows.Forms.UserControl control, you will notice the same result.
>>
Is there a way to detect Design mode versus runtime mode so as to prevent my worker thread from getting started?
<<
This can be done using the DesignMode property.
Thanks,
Stan.
Hi Stan,
Thanks very much! The DesignMode property solved it for me!
Elan
You are welcome, Elan!
Thanks,
Stan.