-2

I have a winform app in C# with has to create an SQLLocalDB instance at first run. I saw that this process was taking some time in some older PC´s and some users thought that the app had crashed. I created a splashscreen form that lets the user know that the app is creating the instance but i dont know how i cant check when the process has ended and close the splashscreen.

I have a class with the following code to create the instance:

static private void ExecCmdInstance()
{
    System.Diagnostics.Process process = new System.Diagnostics.Process();
    System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
    startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    startInfo.FileName = "cmd.exe";
    startInfo.Arguments = "/c sqllocaldb create MSSQLLocalDB -s";
    process.StartInfo = startInfo;
    process.Start();
}

Can anyone point me in the right direction please? Thanks in advance.

septaug
  • 61
  • 11
  • Hook the `Process.Exited` event of your `process` object. – Maximilian Gerhardt Dec 16 '16 at 09:40
  • 2
    Possible duplicate of [C# process.start, how do I know if the process ended?](http://stackoverflow.com/questions/12273825/c-sharp-process-start-how-do-i-know-if-the-process-ended) – Manfred Radlwimmer Dec 16 '16 at 09:40
  • 1
    @Manfred Radlwimmer hi, I see that you marked the question as duplicate. Sure, the post helps in the resolution, but to say it is a duplicate is a stretch. Thanks anyway it helps – septaug Dec 16 '16 at 09:52
  • @septaug Isn't `I don't know how I can check when the process has ended` the exact the same as `how do I know if the process ended`? – Manfred Radlwimmer Dec 16 '16 at 10:10

1 Answers1

0

You could use:

process.WaitForExit();

But be aware that it will block your gui thread. You might start the process on a different thread, so your gui isn't blocked.

Jeroen van Langen
  • 21,446
  • 3
  • 42
  • 57