Solved

Application won't close ...

Posted on 2009-06-29
3
396 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:
Nate Feinberg 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

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…
Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

623 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