closing a windows form by itself
-
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.
-
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.
-
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.
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