Solved

Application won't close ...

Posted on 2009-06-29
3
394 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

685 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