• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

C# problem trying to start another program

I am trying to run the follwoing command

       private void stockCheckToolStripMenuItem_Click(object sender, EventArgs e)
        {

            string str = "";
            Mainfrm Stockcheck = new Mainfrm();
            Stockcheck.ConfigurationVar = ConfigurationVar;
            Stockcheck.LoginScreenVar = LoginScreenVar;
            Stockcheck.AvailableDataBasesVar = AvailableDataBasesVar;
            Stockcheck.InitStockCheck();
            try { Application.Run(Stockcheck); }
            catch (Exception err)
            {
                str = "Application Failed please contact MAC IT";
                ee.MsgBoxE(err, str, "1", 8);
            }

        }

but I get a failure wheren trying to run the command Application.Run(Stockcheck);

I have created a central window for my applicaitons, and the program first starts with a log in screen, this is executed by the program.cs ...

need some help here
0
Jayesh Acharya
Asked:
Jayesh Acharya
2 Solutions
 
Kyle AbrahamsSenior .Net DeveloperCommented:
What's your err mesage?

0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
Maybe you want is this:
private void stockCheckToolStripMenuItem_Click(object sender, EventArgs e)
        {

            string str = "";
            Mainfrm Stockcheck = new Mainfrm();
            Stockcheck.ConfigurationVar = ConfigurationVar;
            Stockcheck.LoginScreenVar = LoginScreenVar;
            Stockcheck.AvailableDataBasesVar = AvailableDataBasesVar;
            Stockcheck.InitStockCheck();
            try {
               Stockcheck.ShowDialog();
             }
            catch (Exception err)
            {
                str = "Application Failed please contact MAC IT";
                ee.MsgBoxE(err, str, "1", 8); 
            }

Open in new window

0
 
brutaldevCommented:
You're doing that code in a click event of your form. Application.Run won't be able to pass control to another form if on is already running.

Based on this I'm guessing you're getting "A main message loop is already running on the current thread."
You should rather just show the form:
...
// Do not do this while a main form is already running.
// Application.Run(Stockcheck);
Stockcheck.Show();
...

Open in new window

0
 
Carlos VillegasFull Stack .NET DeveloperCommented:
I forget a }
private void stockCheckToolStripMenuItem_Click(object sender, EventArgs e)
{
    string str = "";
    Mainfrm Stockcheck = new Mainfrm();
    Stockcheck.ConfigurationVar = ConfigurationVar;
    Stockcheck.LoginScreenVar = LoginScreenVar;
    Stockcheck.AvailableDataBasesVar = AvailableDataBasesVar;
    Stockcheck.InitStockCheck();
    try
    {
        Stockcheck.ShowDialog();
    }
    catch (Exception err)
    {
        str = "Application Failed please contact MAC IT";
        ee.MsgBoxE(err, str, "1", 8);
    }
}

Open in new window

0
 
Jayesh AcharyaTechnichal ConsultantAuthor Commented:
Thanks this was perfect,
the final code
        private void stockCheckToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string str = "";
            Mainfrm Stockcheck = new Mainfrm();
            Stockcheck.ConfigurationVar = ConfigurationVar;
            Stockcheck.LoginScreenVar = LoginScreenVar;
            Stockcheck.AvailableDataBasesVar = AvailableDataBasesVar;
            Stockcheck.InitStockCheck();
            try
            {
                //inside window remove to be outside window
                Stockcheck.MdiParent = this;
                Stockcheck.Show();
            }
            catch (Exception err)
            {
                str = "Application Failed please contact MAC IT";
                ee.MsgBoxE(err, str, "1", 8);
            }

        } //stockCheckToolStripMenuItem_Click


all I need to do now is figure out how to close the child window
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now