locked
Need to Restart visual studio programatically RRS feed

  • Question

  • Hi ,

            Am newer to Vs packages,I have created a Vs Package in which I have a button which will call a exe (eg:Installer.exe)after the exe get executed visual studio should get restart,

    i have used the following snippet

     System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = "Installer.exe";
                p.Start(); 
                var obj = (IVsShell4)this.GetService(typeof(SVsShell));

                   (obj as IVsShell4).Restart((uint)__VSRESTARTTYPE.RESTART_Normal);

    with this code the vs get restarted before the completion of exe's execution.

    what i need is on button click exe should called and some installation shoud be performed based on the exe,after that vs should get restart.anyone please provide solution on this


    Kani


    • Edited by Kani_mozhi Tuesday, September 2, 2014 4:50 PM
    • Moved by Kristin Xie Wednesday, September 3, 2014 1:49 AM
    Tuesday, September 2, 2014 6:34 AM

Answers

  • Try calling:

    try
    {
       p.Start();

       p.WaitForExit(millisecondstimeout); // Ensure you use a timeout!!

       var obj = (IVsShell4)this.GetService(typeof(SVsShell));

       (obj as IVsShell4).Restart((uint)__VSRESTARTTYPE.RESTART_Normal);
    }
    catch (Exception ex)
    {
       // Handle exceptions
       ...

    }


    * My new blog about VSX: http://www.visualstudioextensibility.com * Twitter: https://twitter.com/VSExtensibility * MZ-Tools productivity extension for Visual Studio: http://www.mztools.com.

    Friday, September 5, 2014 10:11 AM

All replies

  • Hi Kani,

    Like the title mentioned, it is a visual studio related case. so I've moved it to Visual Studio Integrate forum for better support.

    Best regards,

    Kristin


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, September 3, 2014 1:52 AM
  • Hi Hasinigopal,

    I don't think you can do that. When you install this VSPackage on your machine, it'll under the control of VS IDE, it's a part of it. If you restart it, the current work will end and it don't have the ability to detect the other process status. Even you create another thread in the button's click event handler, it won't work, either it's a background thread or foreground thread.

    The only way I can think of is to create a stand alone application, but not VSPackage. In this way, the application could detect the status of VS IDE and the installation program.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, September 3, 2014 10:00 AM
  • Try calling:

    try
    {
       p.Start();

       p.WaitForExit(millisecondstimeout); // Ensure you use a timeout!!

       var obj = (IVsShell4)this.GetService(typeof(SVsShell));

       (obj as IVsShell4).Restart((uint)__VSRESTARTTYPE.RESTART_Normal);
    }
    catch (Exception ex)
    {
       // Handle exceptions
       ...

    }


    * My new blog about VSX: http://www.visualstudioextensibility.com * Twitter: https://twitter.com/VSExtensibility * MZ-Tools productivity extension for Visual Studio: http://www.mztools.com.

    Friday, September 5, 2014 10:11 AM
  • Hi Carlos,

                  Its working .Thanks.


    Kani

    Saturday, September 6, 2014 12:58 PM