Click here to Skip to main content
12,623,511 members (32,967 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
Hi all,

I have an issue with a winform. I would like to exit the application using Environment.Exit(1). However when I use this approach the code before the exit code does not execute. Any thoughts? Here is my code. Just as a note, the code runs successfully if I leave out the Environement.Exit(1) code.

public void ShowForm(System.Windows.Forms.Form frm, string id)
{
    frmMain=frm;
    this.Show();
 
    object empty = null;
 
    axW.Navigate("http://localhost:2124/Studiebogservice/_Ankomst/LabelPrint.aspx?id=" + id, ref empty, ref empty, ref empty, ref empty);
 
    for (; axW.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE; )
    {
        System.Windows.Forms.Application.DoEvents();
    }
 
    axW.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, ref empty, ref empty);
 
    Environment.Exit(1);
}
Posted 12-Nov-12 0:33am
Comments
chandanadhikari 12-Nov-12 13:30pm
   
what happens when you debug with breakpoint at Environment.Exit(1)

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

It probably does get cued to run, and the commands for it are prepared - but as an asynchronous process. Then along comes Environment.Exit and terminates all processes associated with the application, including those you have just prepared to print.

Environment.Exit is a big step - it is an abnormal termination, and it shuts everything down, without waiting for them to finish, save data, or do anything else.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161128.1 | Last Updated 12 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100