private void CardCk() { bool absent = false; //Establish Context retCode = ModWinsCard.SCardEstablishContext(ModWinsCard.SCARD_SCOPE_USER, 0, 0, ref hContext); if (retCode == ModWinsCard.SCARD_S_SUCCESS) { while (!Present) { Success = true; RdrState.RdrName = "ACS ACR122 0"; //Check Card Status retCode = ModWinsCard.SCardGetStatusChangeA(this.hContext, 0, ref RdrState, 1); if (retCode == ModWinsCard.SCARD_S_SUCCESS) { Success = true; if ((Convert.ToUInt32(RdrState.RdrEventState) & ModWinsCard.SCARD_STATE_PRESENT) == ModWinsCard.SCARD_STATE_PRESENT) { retCode = ModWinsCard.SCardConnect(hContext, RdrState.RdrName, ModWinsCard.SCARD_SHARE_SHARED, ModWinsCard.SCARD_PROTOCOL_T0 | ModWinsCard.SCARD_PROTOCOL_T1, ref hCard, ref Protocol); if (retCode != ModWinsCard.SCARD_S_SUCCESS) { Success = false; MessageBox.Show(ModWinsCard.GetScardErrMsg(retCode)); } else { Success = true; connActive = true; Present = true; } } if ((Convert.ToUInt32(RdrState.RdrEventState) & ModWinsCard.SCARD_STATE_EMPTY) == ModWinsCard.SCARD_STATE_EMPTY && !absent) { absent = true; connActive = false; } } else { Success = false; MessageBox.Show(ModWinsCard.GetScardErrMsg(retCode)); } } } else { Success = false; MessageBox.Show(ModWinsCard.GetScardErrMsg(retCode)); } OnCardPresent(); OnCardAbsent(); }