private void SetCommStateNative(ref Dcb lpDcb) { int commErrors = 0; Comstat comStat = new Comstat(); for (int i = 0; i < CommStateRetries; i++) { if (!NativeMethods.ClearCommError(m_Handle, ref commErrors, ref comStat)) { WinIoError(); } if (NativeMethods.SetCommState(m_Handle, ref lpDcb)) { break; } if (i == CommStateRetries - 1) { WinIoError(); } } }
private void SetCommStateNative(ref Dcb lpDcb) { var commErrors = 0; var comStat = new Comstat(); for (var i = 0; i < CommStateRetries; i++) { if (!ClearCommError(m_Handle, ref commErrors, ref comStat)) { WinIoError(); } if (SetCommState(m_Handle, ref lpDcb)) { break; } if (i == CommStateRetries - 1) { WinIoError(); } } }
private void GetCommStateNative(ref Dcb lpDcb) { int commErrors = 0; Comstat comStat = new Comstat(); for (int i = 0; i < CommStateRetries; i++) { if (!ClearCommError(_handle, ref commErrors, ref comStat)) { WinIoError(); } if (GetCommState(_handle, ref lpDcb)) { break; } if (i == CommStateRetries - 1) { WinIoError(); } } }
private static void MarshalCommState(SafeFileHandle handle, Func <bool> performCommState) { int commErrors = 0; var comStat = new Comstat(); for (int i = 0; i < CommStateRetries; i++) { if (!ClearCommError(handle, ref commErrors, ref comStat)) { ThrowIoException(); } if (performCommState()) { return; } if (i == CommStateRetries - 1) { ThrowIoException(); } } }
internal static extern bool ClearCommError(SafeFileHandle hFile, ref int lpErrors, ref Comstat lpStat);
private static extern bool ClearCommError(SafeFileHandle hFile, ref int lpErrors, ref Comstat lpStat);