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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:42:45+00:00 2026-06-14T01:42:45+00:00

I have buggy code and I don’t know where or what is the fault.

  • 0

I have buggy code and I don’t know where or what is the fault.

I am writing an application for a customer. During the splash screen the app checks if Mysql is running to be able to connect to it later. If mysql is on, the app continues booting. If mysql is not running I start it and re-check again.

Initially, I was finding the mysql pid, but for some reason I can’t get it without using unmanaged code.

So I found another way in xampp source code and I decided to use it.

Running the app under vstudio debugger stepping or stopping in a breakpoint works perfectly, but if run without stepping, the app boots mysql server but can´t detect it and eventually the application stop (I don’t want the app continue loading if database fails).

This behavior has led me to think that one or more variables are disposed at runtime before I can use it again.

I don’t know how solve this issue and need a hand.

EDIT: The issue was mysql was not started yet running the app without interruption
As Jan & SWEKO said. Adding some delay works perfectly

The splash screen Load code.

// App booting tasks
void Load()
{

 // License validation ok
 Boolean licensecheck = BootChecks.LicenseCheck();

 if (! licensecheck)
 {
   MessageBox.Show("License Error Conta ct Technical Support","Error",MessageBoxButtons.OK,MessageBoxIcon.Stop);
            Application.Exit();
}

bar.Width += 10; // feed progress bar ( it's a custom drawn label )
this.Refresh();  // update form to paint it
Application.DoEvents(); // process all pooled messages

// Mysql check
Boolean dbcheck = BootChecks.DbCheck();

// THE ISSUE IT'S HERE RUNNING WITHOUT STEPPING , ALWAYS FIRES THE ERROR
if ( ! dbcheck )
{
MessageBox.Show("Can't init Mysql. Contact Technical Support", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            Application.Exit();
 }

 bar.Width += 10;
 this.Refresh();
 Application.DoEvents();

 // more stuff

}

Database check code

public static bool DbCheck()
{

Boolean norun = MysqlController.CheckMysqlIsRunning(Constants.dbpidfile);

// check if running
if ( norun ) return true;

// if not running, I start it
MysqlController.StartMysql(Constants.dbexe,Constants.dbopts);

Boolean rerun = MysqlController.CheckMysqlIsRunning(Constants.dbpidfile);

// if really running all it's ok
if ( rerun ) return true;

// really a fault
return false;

}

Real mysql check

comment: this way was found on xampp package. To know if mysql it’s running find mysql pid file, and open a named event. if right definitively mysql it’s running.

public static Boolean CheckMysqlIsRunning(String pathtopidfile)
{
    try
    {
        Int32 pid;
        using ( StreamReader sr = new StreamReader(pathtopidfile) )
        {
            pid = int.Parse(sr.ReadToEnd());
        }

        IntPtr chk = OpenEvent(SyncObjectAccess.EVENT_MODIFY_STATE, false, 
            String.Format("MySQLShutdown{0}", pid.ToString()));

        if ( chk != null ) return true;

        return false;
    }
    catch (Exception) { return false;}
}

public static void StartMysql(String path, String aargs)
{
  // All ok. Simply spawn a 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-06-14T01:42:46+00:00Added an answer on June 14, 2026 at 1:42 am

    You have to code some kind of loop. You start the mysql process and when you check immediately after is, the process is still not there and you return false.

    Try something like this:

    // if not running, I start it
    MysqlController.StartMysql(Constants.dbexe,Constants.dbopts);
    // wait 10 seconds max.
    int timeout = 10;
    bool mySqlIsRunning = false;
    
    while(!MysqlController.CheckMysqlIsRunning(Constants.dbpidfile)) {
        // wait a while
        Thread.Sleep(1000);
        if (timeout-- == 0) {
            // timeout error
            // show message to user ...
        }
    }
    
    // here mysql is running or your timeout is expired.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large C# code base. It seems quite buggy at times, and
We have a .Net application consisting of mixed managed and unmanaged code. We have
I'm trying to make photo album like photo.app in iPhone. I know We have
I'm completely tired of all the buggy code I've been writing for all this
Let's say I have a buggy application like this: using System; namespace ConsoleApplication1 {
I have a buggy xml that contains empty attributes and I have a parser
I have been frustrated that I have had to use the very buggy XCode
From time to time, I'm handed bloated, undocumented, buggy PHP code to fix. I
I have some Visual C++ code that receives a pointer to a buffer with
I'm a one man show developing a C++ Windows application for a customer. Over

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.