Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application.Quit() doesn't quit the application

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'.

like image 211
maialithar Avatar asked Sep 03 '26 01:09

maialithar


1 Answers

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

like image 166
Mark Segal Avatar answered Sep 04 '26 13:09

Mark Segal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!