Solved

Application won't close ...

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

863 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

26 Experts available now in Live!

Get 1:1 Help Now