Solved

How to make a C# executable kill itself when it is finished running?

Posted on 2008-10-16
9
1,186 Views
Last Modified: 2008-10-16
hi all,
i am using a c# executable file to do some jobs. it is running on a certain time everyday. my problem is how to exit the process when it finish doing the job?

i try to kill it in main function, but it does not work. because i check the Task Manager, the process is still there. i have to right click the process in task manager to end it manually. How to end the process automatically? i have to put it in automation server.

[STAThread]

        static void Main()

        {

            Application.EnableVisualStyles();

            Application.SetCompatibleTextRenderingDefault(false);

            Form frm = new Form1();

            Application.Run(frm);//do some jobs

            frm.Close();//finished, then close

            Application.Exit();//exit, but it still stay in Task manager,how to end it automatically?

        }

Open in new window

0
Comment
Question by:viola123
9 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 22737028
do you have some threads?
0
 
LVL 6

Author Comment

by:viola123
ID: 22737112
NO, it is just a simple exe
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 22737133
the last 2 lines are never executed, at least when the main Form exists.
you should put  a timer object in your form and close the form from inside.
0
 
LVL 6

Expert Comment

by:carlsiy
ID: 22737214
you could try using Application.ShowDialog for the form to be opened  rather than Application.Run, and nest the jobs there also with the form exit, so when the application closes the subform it will continue to exit the application
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 6

Author Comment

by:viola123
ID: 22737249
hi,
there is only one form contained. so i have to close this form first? how?
in the form1.cs, write this.close()?
0
 
LVL 6

Author Comment

by:viola123
ID: 22737271
hi,
in form1.cs:
public Form1()
        {
            InitializeComponent();
            Myjob(); //doing some jobs
            this.Close(); // close the form?
        }

pls give me some idea how to fix it?
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 22737301
better try to do it at Load event:
            Myjob(); //doing some jobs
            this.Close(); // close the form?
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 22737424
how are you running your application? through debugger or from the setup you have prepared
if through debugger then whats appearing in the task manager as the exe name
is it projectname.exe or projectname.vshost.exe?

if its vshost.exe then its ok becasue the debugger keeps it open as you can see in you bin folder 2 exes
one a normal projectname.exe and the other projectname.vshost.exe
0
 
LVL 6

Author Comment

by:viola123
ID: 22737491
HI jaime,
that works!!!!! i am very happy with that.

thanks a lot
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now