Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. closing a windows form by itself

closing a windows form by itself

Scheduled Pinned Locked Moved C#
questioncsharp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aakar
    wrote on last edited by
    #1

    Hi I am writing a windows application using C# for performing a task as scheduled. Now I am calling a method which does the needful inside the form1 constructor which is inside the main method like this: static void Main() { System.Windows.Forms.Application.Run(new Form1()); System.Windows.Forms.Application.Exit(); } now what is happenning is that the control does not reach this statement System.Windows.Forms.Application.Exit(); and I need to manually close the form which is not what I want. I want the application (and the form) to close by itself. How can i do this. Thanks in advance, Aryan.

    A D 2 Replies Last reply
    0
    • A aakar

      Hi I am writing a windows application using C# for performing a task as scheduled. Now I am calling a method which does the needful inside the form1 constructor which is inside the main method like this: static void Main() { System.Windows.Forms.Application.Run(new Form1()); System.Windows.Forms.Application.Exit(); } now what is happenning is that the control does not reach this statement System.Windows.Forms.Application.Exit(); and I need to manually close the form which is not what I want. I want the application (and the form) to close by itself. How can i do this. Thanks in advance, Aryan.

      A Offline
      A Offline
      albCode
      wrote on last edited by
      #2

      Set timers to enabled true private void timer1_Tick(object sender, System.EventArgs e) { Application.Exit(); }

      1 Reply Last reply
      0
      • A aakar

        Hi I am writing a windows application using C# for performing a task as scheduled. Now I am calling a method which does the needful inside the form1 constructor which is inside the main method like this: static void Main() { System.Windows.Forms.Application.Run(new Form1()); System.Windows.Forms.Application.Exit(); } now what is happenning is that the control does not reach this statement System.Windows.Forms.Application.Exit(); and I need to manually close the form which is not what I want. I want the application (and the form) to close by itself. How can i do this. Thanks in advance, Aryan.

        D Offline
        D Offline
        Darren_
        wrote on last edited by
        #3

        System.Windows.Forms.Application.Exit(); does not get executed because your program is running an open window on a thread. It will never reach System.Windows.Forms.Application.Exit(); because when you close the window Dispose would have been called already. Can i ask why you are using a window? If it is to run a scheduled task why not just create a Console Application, this will exit once it has finished executing. If you have the window so you can enter data about what it is you want to run, why not just add switches to execution of your console application like Start -> Run 'myapp.exe "path to filename" "time to start"' Like this: http://www.codeproject.com/csharp/deleteold.asp?df=100&forumid=152583&exp=0&select=1169916[^] Darren

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups