Hi Daniel,
Thanks so much for the response. Here is a bit more precision, I hope.
I'm making use of this handy utility so I can log debug messages to
the command line on my development laptop ->
http://www.codeproject.com/csharp/compacttcptrace.asp?df=100&forumid=24359&exp=0&select=846907
This builds a .dll which I include in my application. It has a static
method to initialize itself where it reads an xml config file to get
the IP/Port of the remote console, and makes a TCP socket connection to
it.
This is expensive and timely when starting up my application. So I do
the following in my main form:
private Thread debug = null;
private void MainForm_Load(object sender, EventArgs e) {
#if DEBUG
debug = new Thread(new ThreadStart(initDebugConsole));
debug.Start();
#endif
}
private void initDebugConsole() {
// for debugging to a remote console
try {
TcpTraceListener.InstallTcpTraceListener();
Debug.WriteLine("Debug Console Ready...");
} catch (Exception e) {
/*
* try/catch block here, b/c if you don't have the tcp
server
* running to catch debug log statements, it crashes
the app.
*/
SetText(e.Message);
}
}
There is no while loop in the method for that ThreadStart, so once it
completes, it should complete. I believe the reason it hangs when I
try to re-deploy is that the socket is still open, despite the
TcpTraceListener code having the following:
public override void Close() {
if (stream != null) {
try {
SendString(end);
stream.Flush();
stream.Close();
stream = null;
} catch {
}
}
if (tcpClient != null) {
try {
tcpClient.Close();
tcpClient = null;
} catch (Exception) {
}
}
}
public void Dispose() {
Close();
}
I even added a static ShutDown( ) method to the TcpTraceListener code
that does the same thing:
public static void ShutDown() {
if (stream != null) {
SendString(end);
stream.Flush();
stream.Close();
stream = null;
}
if (tcpClient != null) {
tcpClient.Close();
tcpClient = null;
}
}
and in my form I do the following:
private Boolean shutdown() {
SetText("Shutting down....");
try {
TcpTraceListener.ShutDown( );
} catch (Exception) {
return false;
}
return true;
}
/// <summary>
/// Callback when form is closing
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected override void OnClosing(CancelEventArgs e) {
e.Cancel = shutdown();
base.OnClosing(e);
}
I guess the only thing I haven't commented on is the SendString(end);
call above in the ShutDown method -- this sends a poison pill to the
server to indicate the session is closing, so the server can print a
msg to the console that the client shut down.
If you can spot something in here that can cause the socket to stay
open, I'd love to hear it.
Thanks much in advance,
Davis