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 8985017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:14:38+00:00 2026-06-15T21:14:38+00:00

All, I have an application I want to lanch from another application or as

  • 0

All, I have an application I want to lanch from another application or as a stand alone utility. To facilitate the start up of appA from appB, I use the following code in Main()/Program.cs

[STAThread]
static void Main(string[] args)
{
    Application.EnableVisualStyles();
    Application.SetCompatibleTextRenderingDefault(false);
    Application.Run(new SqlEditorForm(args));
} 

Now, in SqlEditorForm I have two constructors

public SqlEditorForm(string[] args)
    : this()
{
    InitializeComponent();

    // Test if called from appB...
    if (args != null && args.Count() > 0)
    {
        // Do stuff here...
    }
}

and the deafult

public SqlEditorForm()
{
    // Always do lots of stuff here...
}

This to me looks fine, but when run as stand alone (args.Length = 0) the SqlEditorForm(string[] args) constructor is getting called, and before it steps into the constructor to perform InitializeComponent();, it goes and initialises all of the global variables for the class then steps directly into the default constructor.

Question, The chaining of the constructors seems to be happending in the wrong order. I want to know why?

Thanks for your time.

  • 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-06-15T21:14:40+00:00Added an answer on June 15, 2026 at 9:14 pm

    Move all logic to constructor with parameter and call that constructor from parameterless one, passing default parameter value:

    public SqlEditorForm()
        :this(null)
    {        
    }
    
    public SqlEditorForm(string[] args)
    {   
        InitializeComponent();
        // Always do lots of stuff here...
    
        if (args != null && args.Count() > 0)
        {
            // Do stuff here...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In our ColdFusion application we have stateless model objects. All the data I want
I want to get all the Applications that have intentlisteners to Intent.CATEGORY_HOME so basically
My application has several independent top-level windows, which all have completely different functions/workflows. I
I have this application that will recurse all folders in a given directory and
I have an application which needs to loop through all the lines in text
I have an application with tabs that are all webviews. I'm using UIWebViewDelegate so
I have the application in which user select the particular folder and all the
I have an application that is going to work like a p2p-software where all
We have an application written in both C++ and .NET that installs for all
I have an application that plays back video frame by frame. This is all

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.