Solved

Application won't close ...

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
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 gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
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…

762 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

22 Experts available now in Live!

Get 1:1 Help Now