Click here to Skip to main content
15,886,110 members
Home / Discussions / C#
   

C#

 
GeneralRe: Help with file search Pin
Not Active20-Jan-11 13:23
mentorNot Active20-Jan-11 13:23 
GeneralRe: Help with file search Pin
turbosupramk320-Jan-11 13:49
turbosupramk320-Jan-11 13:49 
AnswerRe: Help with file search Pin
Yusuf20-Jan-11 16:09
Yusuf20-Jan-11 16:09 
QuestionNodes, Script interface/ API and Undo Pin
adamvanner20-Jan-11 8:47
adamvanner20-Jan-11 8:47 
AnswerRe: Nodes, Script interface/ API and Undo Pin
SledgeHammer0120-Jan-11 9:51
SledgeHammer0120-Jan-11 9:51 
GeneralRe: Nodes, Script interface/ API and Undo Pin
adamvanner20-Jan-11 22:43
adamvanner20-Jan-11 22:43 
QuestionAccessing variables during AppDomain.ProcessExit Pin
thatdiceygirl20-Jan-11 5:16
thatdiceygirl20-Jan-11 5:16 
AnswerRe: Accessing variables during AppDomain.ProcessExit Pin
Luc Pattyn20-Jan-11 5:46
sitebuilderLuc Pattyn20-Jan-11 5:46 
Hi Jenni,

Application.Exit() and its event handler work just fine for me. Here is an example (using a Form with a Button and a Label):
using System;
using System.ComponentModel;
using System.IO;
using System.Windows.Forms;

namespace WindowsFormsApplication2 {
	public partial class Form1 : Form {
		public Form1() {
			InitializeComponent();
			log("start");
			Application.ApplicationExit+=delegate(object sender, EventArgs e) {
				string s=SomeTrace.TraceLog;
				label1.Text="all logs: "+s;
				MessageBox.Show(s);
				File.WriteAllText("log.txt", s);
			};
		}

		private void log(string s) {
			label1.Text=s;
			SomeTrace.log(s);
		}

		private void btnQuit_Click(object sender, EventArgs e) {
			log("btnQuit_Click");
			Application.DoEvents();
			Application.Exit();
		}
	}

	public class SomeTrace {
		public static string TraceLog=DateTime.Now.ToLongTimeString();
		public static void log(string s) {
			TraceLog+=Environment.NewLine+s;
		}
	}
}


Note the behavior depends on how the app quits: closing the main form just creates the file, there will not be a MessageBox as the main form is no longer present. Clicking the Button closes the main form (due to the exit) AND shows the MessageBox.

Remarks:
1. you don't need Flush before a Close;
2. if something is already a string (I suspect TraceString is), there is no use in calling it's ToString() method;
3. I wouldn't use a static trace object, I'd rather instantiate one and pass it along

Smile | :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

GeneralRe: Accessing variables during AppDomain.ProcessExit Pin
thatdiceygirl20-Jan-11 5:56
thatdiceygirl20-Jan-11 5:56 
AnswerRe: Accessing variables during AppDomain.ProcessExit Pin
Luc Pattyn20-Jan-11 6:05
sitebuilderLuc Pattyn20-Jan-11 6:05 
GeneralRe: Accessing variables during AppDomain.ProcessExit Pin
thatdiceygirl20-Jan-11 6:27
thatdiceygirl20-Jan-11 6:27 
AnswerRe: Accessing variables during AppDomain.ProcessExit Pin
Luc Pattyn20-Jan-11 6:37
sitebuilderLuc Pattyn20-Jan-11 6:37 
QuestionDatabase back up from asp.net Pin
yesu prakash20-Jan-11 1:02
yesu prakash20-Jan-11 1:02 
AnswerRe: Database back up from asp.net Pin
Richard MacCutchan20-Jan-11 1:54
mveRichard MacCutchan20-Jan-11 1:54 
GeneralRe: Database back up from asp.net Pin
yesu prakash20-Jan-11 17:15
yesu prakash20-Jan-11 17:15 
GeneralRe: Database back up from asp.net Pin
yesu prakash20-Jan-11 17:16
yesu prakash20-Jan-11 17:16 
GeneralRe: Database back up from asp.net Pin
Mahendra Vishwakarma20-Jan-11 20:37
Mahendra Vishwakarma20-Jan-11 20:37 
GeneralRe: Database back up from asp.net Pin
Richard MacCutchan20-Jan-11 21:30
mveRichard MacCutchan20-Jan-11 21:30 
QuestionRe: Database back up from asp.net Pin
Paladin200020-Jan-11 4:04
Paladin200020-Jan-11 4:04 
AnswerRe: Database back up from asp.net Pin
Mahendra Vishwakarma20-Jan-11 20:36
Mahendra Vishwakarma20-Jan-11 20:36 
QuestionSetup and File association Pin
Eduard Keilholz20-Jan-11 0:09
Eduard Keilholz20-Jan-11 0:09 
AnswerRe: Setup and File association Pin
GenJerDan20-Jan-11 3:40
GenJerDan20-Jan-11 3:40 
GeneralRe: Setup and File association Pin
Eduard Keilholz20-Jan-11 21:00
Eduard Keilholz20-Jan-11 21:00 
AnswerRe: Setup and File association Pin
J a a n s20-Jan-11 16:57
professionalJ a a n s20-Jan-11 16:57 
GeneralRe: Setup and File association Pin
Eduard Keilholz20-Jan-11 21:02
Eduard Keilholz20-Jan-11 21:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.