Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To add dispose. #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions ThaiNationalIDCard/ThaiIDCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,17 +188,19 @@ private byte[] SendCommand(byte [] command)

private byte[] SendPhotoCommand()
{
var s = new MemoryStream();
byte[][] cmds_photo = _apdu.EF_CARD_PHOTO;

for (int i = 0; i < cmds_photo.Length; i++)
using (var s = new MemoryStream())
{
s.Write(SendCommand(cmds_photo[i]), 0, SendCommand(cmds_photo[i]).Length);
eventPhotoProgress?.Invoke(i + 1, cmds_photo.Length);
}
byte[][] cmds_photo = _apdu.EF_CARD_PHOTO;

for (int i = 0; i < cmds_photo.Length; i++)
{
s.Write(SendCommand(cmds_photo[i]), 0, SendCommand(cmds_photo[i]).Length);
eventPhotoProgress?.Invoke(i + 1, cmds_photo.Length);
}

s.Seek(0, SeekOrigin.Begin);
return s.ToArray();
s.Seek(0, SeekOrigin.Begin);
return s.ToArray();
}
}


Expand Down Expand Up @@ -330,8 +332,8 @@ public Boolean Close()
{
try
{
_reader.Disconnect(SCardReaderDisposition.Leave);
_hContext.Release();
_reader?.Disconnect(SCardReaderDisposition.Leave);
_hContext?.Release();
return true;
}
catch (PCSCException ex)
Expand All @@ -341,6 +343,13 @@ public Boolean Close()
Debug.Print(_error_message);
return false;
}
finally
{
_hContext?.Dispose();
_reader?.Dispose();
_reader = null;
_hContext = null;
}
}

public Personal readCitizenid(string readerName = null)
Expand Down