TheSwamp

Code Red => .NET => Topic started by: teslaxx on January 26, 2011, 05:28:16 AM

Title: How can I stop my application, from a method?
Post by: teslaxx on January 26, 2011, 05:28:16 AM
So, how can I exit my application, from a method?  :)
Code: [Select]
[CommandMethod("myApp")]
public static void Kilometreaza54()
{
    sub();
}

private static void sub()
{
   // here I want to stop my application in Autocad
}
Title: Re: How can I stop my application, from a method?
Post by: Jeff H on January 26, 2011, 05:44:11 AM
This is one way, but probably a better way

Code: [Select]
[CommandMethod("myApp")]
        public static void Kilometreaza54()
        {
            sub();
        }

        private static void sub()
        {
            Autodesk.AutoCAD.ApplicationServices.Application.Quit();
        }
Title: Re: How can I stop my application, from a method?
Post by: dan.glassman on January 26, 2011, 01:32:04 PM
Your application is a separate .exe outside AutoCAD?

Look into System.Diagnostics.Process

Something like...

Code: [Select]
Process[] myRunningApps = Process.GetProcessByName("myapplicationname");
foreach (Process p in myRunningApps)
{
   if (p.HasExited) continue;

   if (p.CloseMainWindow())
   {
      p.Close()
   }   
   else
   {
      try
      {
         p.Kill()
      }
      catch
      {
         // meh
      }
   }
}


-drg