protected static void CreateSocket(InnerSafeCloseSocket socket, SafeCloseSocket target) { if (socket != null && socket.IsInvalid) { target.SetHandleAsInvalid(); return; } bool b = false; try { socket.DangerousAddRef(ref b); } catch { if (b) { socket.DangerousRelease(); b = false; } } finally { if (b) { target.SetInnerSocket(socket); socket.Dispose(); } else { target.SetHandleAsInvalid(); } } }