Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 406401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T17:29:34+00:00 2026-05-12T17:29:34+00:00

Background : I have created this UserControl. In the constructor of the user control

  • 0

Background:
I have created this UserControl. In the constructor of the user control I call a function that retrieves some values from the database. If an error occurs while retrieving the values a messagebox explaining the error is shown. So far so good.

The Problem:
I have created a form that (among other elements) includes my UserControl. Now when I open this form (or even the UserControl itself) the constructor is called (I suppose so it can be drawn accurately) and, because the database is unavailable, the messagebox (explained above) is shown.

How do I prevent this from happening?

I just want to be clear: the code works great in runtime. Everything is as designed. It is only in Designer view of Visual Studio (2008 SP1 if it matters) where the problem occurs. However in Designer it is awful, especially now when the application attempts to reconnect when the connection fails. Every time I go in to Designer mode my Visual Studio freezes for about 20 seconds (timeout of the reconnect) and it is killing my work process.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T17:29:35+00:00Added an answer on May 12, 2026 at 5:29 pm

    I get around this by having a global static property on my Program class called IsRunning.

    When my program starts up in the main method I set the IsRunning property to true. Then in the constructor of my user control I am able to poll the property IsRunning to determine whether or not I execute particular code, in your case code that would attempt to access a database…

    EDIT:
    Here is some code…

    private static bool _running = false;
    
        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="Program"/> is running.
        /// This property is used for design time WSOD issues and is used instead of the 
        /// DesignMode property of a control as the DesignMode property has been said to be
        /// unreliable.
        /// </summary>
        /// <value><c>true</c> if running; otherwise, <c>false</c>.</value>
        public static bool Running
        {
            get
            {
                return _running;
            }
        }
    
    
        static void Main(string[] args)
        {
            Initialize();
    
    
            _running = true;
    

    ….

    In my user control…

        public AssignmentList()
        {
            InitializeComponent();
    
            if (!Program.Running)
            {
                return;
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created successfully a wpf user control inheritance like this: <base:BaseUserControl x:Class=wpfcontrolinheritance.InheritedUserControl xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation
Background: we have an application that generates reports from HTML (that may or may
I have got a C# user control, which has got it's own background worker
I am developing a WPF application, and I have created a user control called
I am trying to set twoway binding on a UserControl that I have created.
I have a recursively defined user control that needs the following properties: there are
I have an HTML page. I have created a frame using background repeat function.
I am using MVVM Light. I have created a window that looks like this:
I have created a user control in Silverlight which basically animates the size of
Background: I have a kubuntu laptop right now that I can't use wirelessly, i.e.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.