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.