From e79ac8946a0f40ae313dd1d1994390da4bca9690 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Wed, 1 Feb 2012 17:45:43 +0100 Subject: [PATCH] Fixed NullReferenceException that would occur if a client is Dispose()d before a Connect() has succeeded. This typically happens when using the using() construct: using (var pop3 = new Pop3Client()) { pop3.Connect(...); # Fails for some reason } # Throws a NullReferenceException here --- Pop3Client.cs | 5 ++++- TextClient.cs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Pop3Client.cs b/Pop3Client.cs index 97a5c05..3909068 100644 --- a/Pop3Client.cs +++ b/Pop3Client.cs @@ -15,7 +15,10 @@ internal override void OnLogin(string username, string password) { } internal override void OnLogout() { - SendCommand("QUIT"); + if (_Stream != null) + { + SendCommand("QUIT"); + } } internal override void CheckResultOK(string result) { diff --git a/TextClient.cs b/TextClient.cs index 5688c36..8d1af8e 100644 --- a/TextClient.cs +++ b/TextClient.cs @@ -122,7 +122,7 @@ public void Disconnect() { _Stream.Dispose(); _Stream = null; } - if (!_ReadThread.Join(2000)) { + if (_ReadThread != null && !_ReadThread.Join(2000)) { _ReadThread.Abort(); } }