Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C# (http://www.programmingforums.org/forum16.html)
-   -   Program not closing? (http://www.programmingforums.org/showthread.php?t=15575)

Kilo Apr 8th, 2008 6:13 PM

Program not closing?
 
Why is it that in debug/runtime after exiting my application I either have to hit stop in debug or use the task manager to actually stop the program from running?
The program uses sockets. Is it possible one is being left open or is there another general reason why this happens?

Thanks

kruptof Apr 8th, 2008 6:33 PM

Re: Program not closing?
 
Is your application creating any threads, if so it could be some thread is refusing to terminate cause it's still working. Check this ebook out, I think it explains the procedure involved closing a thraed

crawforddavid2006 Apr 9th, 2008 10:02 PM

Re: Program not closing?
 
if you are closing the program in a window that is not the original window that was created when you hit run, then you have to press the stop button.

Kilo Apr 18th, 2008 3:28 PM

Re: Program not closing?
 
Quote:

Originally Posted by kruptof (Post 143665)
Is your application creating any threads, if so it could be some thread is refusing to terminate cause it's still working. Check this ebook out, I think it explains the procedure involved closing a thraed

Yes it's a multi-socket app which uses a thread for each connection. I will read the e-book and post my findings.

Thanks


Quote:

Originally Posted by crawforddavid2006 (Post 143706)
if you are closing the program in a window that is not the original window that was created when you hit run, then you have to press the stop button.

I'm aware of the stop button, thanks. My problem also occurs outside of the debugger when the [X] is hit. The process can still be found in the task manager list. (and no I'm not referring to the vhost.exe)

Kilo Apr 18th, 2008 3:47 PM

Re: Program not closing?
 
I'm still having the same issue. This is my deconstructor and my RemoveClient method.

:

  1.         ~xsocket()
  2.         {
  3.             if (b_isServer)
  4.                 tcp_listener.Stop();
  5.             if (thd_dataReader != null)
  6.             {
  7.                 if (thd_dataReader.IsAlive)
  8.                 {
  9.                     Thread.Sleep(1000);
  10.                     thd_dataReader.Abort();
  11.                     thd_dataReader.Join(100);
  12.                 }
  13.             }
  14.             if (thd_tcp != null)
  15.             {
  16.                 if (thd_tcp.IsAlive)
  17.                 {
  18.                     Thread.Sleep(1000);
  19.                     thd_tcp.Abort();
  20.                     thd_tcp.Join(100);
  21.                 }
  22.             }
  23.         }
  24.  
  25.         public void RemoveClient(int client)
  26.         {
  27.             s_newLine = hash_nicks[client] + "(" + client.ToString() + ") has exited.";
  28.  
  29.             if (tb_chatBox.InvokeRequired)
  30.                 tb_chatBox.Invoke(new DataPost(OnDataPost));
  31.  
  32.             Socket sock_closer = (Socket)hash_sockets[client];
  33.  
  34.             sock_closer.Close();
  35.  
  36.             Thread thd_removeClient = (Thread)hash_threads[client];
  37.             hash_sockets.Remove(client);
  38.             hash_threads.Remove(client);
  39.             hash_nicks.Remove(client);
  40.  
  41.             try
  42.             {
  43.                 if (thd_removeClient.IsAlive)
  44.                 {
  45.                     Thread.Sleep(1000);
  46.                     thd_removeClient.Abort();
  47.                     thd_removeClient.Join(100);
  48.                 }
  49.             }
  50.             catch { }
  51.  
  52.             GC.Collect();
  53.         }


Alias Apr 23rd, 2008 11:28 PM

Re: Program not closing?
 
To cleanup managed resources derive from IDisposable and carry out your routine in the implementation of the Dispose method. Destructors should be used to cleanup unmanaged resources and wont work as you probably expect for managed types.


All times are GMT -5. The time now is 4:21 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC