Donald C

Donald C

  • 1.5k
  • 153
  • 3.2k

HDI send a final msg via TcpClient before my class closes?

May 3 2016 8:56 AM
Hi Guys,
 
Im having trouble sending a final command to a service before my class closes. 
I have a startupclient that starts when my application starts and attempts to send a "QUIT" message from the class destructor as the class is closing.
Unfortunately when calling SendCommand("QUIT") from the class destructor, I get an exception from the SendCommand method.
 
System.ObjectDisposedException was unhandled
HResult=-2146232798
Message=Cannot access a disposed object.
Object name: 'System.Net.Sockets.TcpClient'.
ObjectName=System.Net.Sockets.TcpClient
Source=System
StackTrace:
at System.Net.Sockets.TcpClient.GetStream()
at Skeleton.Classes.clsStartupClient.SendCommand(String Command, String Param)
at Skeleton.Classes.clsStartupClient.SendCommand(String Command)
at Skeleton.Classes.clsStartupClient.Finalize()
InnerException:
on the line below in the SendCommand() method.
StreamWriter wtr = new StreamWriter(Cli.GetStream()); 
 
 
 
How would I be able to send a final SendCommand message before the class closes?
 
Thanks in advance. 
 
 

Attachment: Startup.zip

Answers (2)