Digital Personna SDK跨线程操作无效:从创建控件的线程以外的线程访问控件
本文关键字:线程 控件 创建 访问 SDK Personna 操作 无效 Digital | 更新日期: 2023-09-27 18:29:46
当我试图关闭它抛出的表单时,我正在使用Digital persona SDK进行此练习
跨线程操作无效:从其他线程访问控件而不是在上创建的线程
该代码用于登录
SqlConnection dataBaseConnection = new SqlConnection("Data Source=.''sqlexpress;Initial Catalog=DemoDB;Integrated Security=True");
public delegate void OnTemplateEventHandler(DPFP.Template template);
Timer closeTimer = new Timer();
DPFP.Capture.Capture Capturer = new DPFP.Capture.Capture();
public login()
{
InitializeComponent();
closeTimer.Tick+=new EventHandler(closeTimer_Tick);
}
private DPFP.Template Template;
private DPFP.Verification.Verification Verificator;
int time = 0;
protected virtual void Init()
{
Capturer = new DPFP.Capture.Capture();
Capturer.EventHandler = this;
Verificator = new DPFP.Verification.Verification(); // Create a fingerprint template verificator
}
protected void start()
{
Capturer.StartCapture();
}
protected virtual void Process(DPFP.Sample sample)
{
drawPicture(convertingToBitmap(sample));
// Process the sample and create a feature set for the enrollment purpose.
DPFP.FeatureSet features = ExtractFeatures(sample, DPFP.Processing.DataPurpose.Verification);
// Check quality of the sample and start verification if it's good
// TODO: move to a separate task
if (features != null)
{
// Compare the feature set with our template
DPFP.Verification.Verification.Result result = new DPFP.Verification.Verification.Result();
Verificator.Verify(features, Template, ref result);
if (result.Verified)
{
MessageBox.Show("Login Success.");
this.Close(); // This the place where the exception is thrown
}
else
MessageBox.Show("The fingerprint was NOT VERIFIED.");
}
}
protected void stop()
{
Capturer.StopCapture();
}
protected DPFP.FeatureSet ExtractFeatures(DPFP.Sample Sample, DPFP.Processing.DataPurpose Purpose)
{
DPFP.Processing.FeatureExtraction Extractor = new DPFP.Processing.FeatureExtraction(); // Create a feature extractor
DPFP.Capture.CaptureFeedback feedback = DPFP.Capture.CaptureFeedback.None;
DPFP.FeatureSet features = new DPFP.FeatureSet();
Extractor.CreateFeatureSet(Sample, Purpose, ref feedback, ref features); // TODO: return features as a result?
if (feedback == DPFP.Capture.CaptureFeedback.Good)
return features;
else
return null;
}
private void drawPicture(Bitmap image)
{
this.Invoke(new Function(delegate()
{
fingerprintImage.Image = new Bitmap(image, fingerprintImage.Size);
}));
}
protected Bitmap convertingToBitmap(DPFP.Sample sample)
{
DPFP.Capture.SampleConversion convertor = new DPFP.Capture.SampleConversion();
Bitmap img = null;
convertor.ConvertToPicture(sample, ref img);
return img;
}
#region EventHandler Members:
public void OnComplete(object Capture, string ReaderSerialNumber, DPFP.Sample Sample)
{
//MakeReport("The fingerprint sample was captured.");
Process(Sample);
closeTimer.Start();
}
public void OnFingerGone(object Capture, string ReaderSerialNumber)
{
// MakeReport("The finger was removed from the fingerprint reader.");
}
public void OnFingerTouch(object Capture, string ReaderSerialNumber)
{
// MakeReport("The fingerprint reader was touched.");
}
public void OnReaderConnect(object Capture, string ReaderSerialNumber)
{
//MakeReport("The fingerprint reader was connected.");
}
public void OnReaderDisconnect(object Capture, string ReaderSerialNumber)
{
MessageBox.Show("The fingerprint reader was disconnected.");
}
public void OnSampleQuality(object Capture, string ReaderSerialNumber, DPFP.Capture.CaptureFeedback CaptureFeedback)
{
//if (CaptureFeedback == DPFP.Capture.CaptureFeedback.Good)
// MakeReport("The quality of the fingerprint sample is good.");
//else
// MakeReport("The quality of the fingerprint sample is poor.");
}
#endregion
使用精细函数
delegate void Function();
this.Invoke(new Function(delegate()
{
this.Close();
}));
问题解决了。
只需使用一行代码。我已经在SDK中进行了测试。它就像一个符咒!
this.Invoke(新MethodInvoker(this.Close));
所以你的代码将是
如果(结果已验证)
{
MessageBox.Show("Login Success."); this.Invoke(new MethodInvoker(this.Close));
}
您可能需要为MethodInvoker 添加下面提到的命名空间
使用System.Windows.Forms;