Application.Quit() doesn't quit the application

maialithar picture maialithar · Dec 28, 2012 · Viewed 9.7k times · Source

I have this simple piece of code in C# with GTK#:

Main.cs:

using System;
using Gtk;

namespace Apu{
    class MainClass{
        public static void Main(string[] args){
            Application.Init();
            new ShowForm();
            Application.Run();
        }
    }
}

ShowForm.cs

public partial class ShowForm: Gtk.Window{  
    public ShowForm(): base(Gtk.WindowType.Toplevel){
        MessageDialog md = new MessageDialog(
            this, 
            DialogFlags.DestroyWithParent, 
            MessageType.Error,
            ButtonsType.None,
            "Test"
        );

        md.SetPosition(Gtk.WindowPosition.CenterAlways);
        md.Title = "Test window";
        md.AddButton("Don't stop", ResponseType.Ok);
        md.AddButton("Stop", ResponseType.Cancel);

        ResponseType result = (ResponseType)md.Run();

        if (result.Equals(ResponseType.Cancel)) {
            Console.WriteLine("Quit!");
            md.DestroyEvent += delegate {
                Application.Quit();
            };
            /*md.DeleteEvent += delegate {
                Application.Quit();
            };*/
        }

        md.Destroy();
    }
}

Console outputs Quit!, but the program doesn't quit. Neither DestroyEvent nor DeleteEvent works. Can anyone explain why? This is my first app in c#, my first time using gtk#. I use monodevelop as my IDE.

EDIT

Application.Exit() gives error: Gtk.Application does not contain a definition for 'Exit'.

Answer

Mark Segal picture Mark Segal · Dec 28, 2012

If you wish to close the process, try Environment.Exit(0)