How to implement the Dispose pattern when my class contains a socket & event?
Should it be something like this?
class MyClass
{
Socket m_ListenerSocket = new Socket();
book m_Disposed=false;
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool isDisposing)
{
if (!m_Disposed)
{
if (isDisposing)
{
if (m_ListenerSocket != null)
{
m_ListenerSocket.Dispose();
innerClass.Notify -= Notify;
}
}
//finalized unmanged code here
m_Disposed = true;
}
}
~MyClass()
{
Dispose(false);
}
}
I'm confused... is socket class is "managed code c# version of winSock"? so it should be released in case of user called dispose ("isDisposing IS true") what about event handlers?
so at finalized comment section should free only Inptr objects? Thanks.