Solved

Application won't close ...

Posted on 2009-06-29
3
392 Views
Last Modified: 2013-12-17
The code below comes from an application that currently runs just like any other Windows program.  It's written in C#, VS 2008, for the .Net 2.0 framework.

I need to add functionality such that if it is started with a command line argument, it is run unattended, i.e., it is not visible, goes directly to the method normally called by a click on a button, then shuts down.

I can't get it to shut down.  When I put Application.Exit(); after this.ReportProduction(); it still does not shut down.

What should I do?
public frmMain(string [] args)
        {
 
            InitializeComponent();
 
            if (args.Length != 0)
            {
                //running from scheduler
                this.btnNow.Visible = false;
                this.Opacity = 0;
                this.ShowInTaskbar = false;
                //every place that statlab or statlab2 is referenced while reporting production
                //  is inapproriate if unattended, and need to write to a log file instead
                this._Unattended = true;
                this.ReportProduction();
            }
        }

Open in new window

0
Comment
Question by:g_johnson
3 Comments
 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 24739891
Hard to say without seeing the rest of the code.  You must have a thread still running
0
 
LVL 8

Accepted Solution

by:
InternalStatic earned 500 total points
ID: 24739897
I've found the Application.Exit() dosen't always kill all of the running threads. Try one of the following--they should work equally well.
Hope I helped,
Nate

System.Diagnostics.Process.GetCurrentProcess().Kill();
Environment.Exit(0);

Open in new window

0
 
LVL 4

Author Closing Comment

by:g_johnson
ID: 31598101
Thanks -- kill worked
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

831 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