Donald C

Donald C

  • 1.9k
  • 109
  • 2.1k

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
Message=Cannot access a disposed object.
Object name: 'System.Net.Sockets.TcpClient'.
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()
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. 


Answers (2)