Author Topic: How can I stop my application, from a method?  (Read 1993 times)

0 Members and 1 Guest are viewing this topic.

teslaxx

  • Guest
How can I stop my application, from a method?
« 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
}

Jeff H

  • Needs a day job
  • Posts: 6144
Re: How can I stop my application, from a method?
« Reply #1 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();
        }

dan.glassman

  • Guest
Re: How can I stop my application, from a method?
« Reply #2 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