Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm writting a fingerprint application using an SDK i downloaded online, SourceAFIS. I noticed that the template extraction took a while to complete, causing the GUI to freeze and sometimes shows ''Not Responding'' so i thought using a backgroundworker would solve my problem but it still didn't help out. The extraction takes approximately 3 seconds per fingerprint sample. Please how can i get that hangging to stop, it makes the application look bad. Thanks
This is an extract.
C#
<pre>private void enroll_Click(object sender, EventArgs e)
        {
            if (enrollmentWorkerBW.IsBusy == false)
            {
                enroll.Enabled = false;
                enroll.Text = "Wait !";
                progressPB.Visible = true;
                enrollmentWorkerBW.RunWorkerAsync();
            }
            else
            {
                MessageBox.Show("Enrollment is already Running","Enrollment Message",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
        }


private void enrollmentWorkerBW_DoWork(object sender, DoWorkEventArgs e)
        {
            this.Invoke(new Function(delegate()
            {
                AfisEngine AFIS = new AfisEngine();
                

                    Bitmap bitmap = null;
                    DPFP.Capture.SampleConversion Convertor = new DPFP.Capture.SampleConversion();	// Create a sample convertor.
                    Fingerprint fingerprint;

                    for (int i = 0; i < printTemplates.Length; i++)
                    {
                        switch (i + 1)
                            {
                                case 1:
                                    getTemplate(printTemplates[i], ref T_thumbR, (i + 1));
                                    //getPartialPrintsTemplate(printSamples[i], ref partial_T_thumbR, (i + 1));
                                    getSample(printSamples[i], ref S_thumbR, (i + 1));
                                    bitmap = null;
                                    Convertor.ConvertToPicture(printSamples[i], ref bitmap);
                                    fingerprint = new Fingerprint();
                                    fingerprint.BitmapImage = bitmap;
                                    //st.Start();
                                    AFIS.Extract(fingerprint);
                                    if (fingerprint.Template != null)
                                        partial_T_thumbR = fingerprint.Template;
                                    else
                                        partial_T_thumbR = null;

                                    break;
                                case 2:
                                    getTemplate(printTemplates[i], ref T_indexR, (i + 1));
                                    //getPartialPrintsTemplate(printSamples[i], ref partial_T_indexR, (i + 1));
                                    getSample(printSamples[i], ref S_indexR, (i + 1));
                                    bitmap = null;
                                    Convertor.ConvertToPicture(printSamples[i], ref bitmap);
                                    fingerprint = new Fingerprint();
                                    fingerprint.BitmapImage = bitmap;
                                    //st.Start();
                                    AFIS.Extract(fingerprint);
                                    if (fingerprint.Template != null)
                                        partial_T_indexR = fingerprint.Template;
                                    else
                                        partial_T_indexR = null;

                                    break;
                                case 3:
                                    getTemplate(printTemplates[i], ref T_middleR, (i + 1));
                                    //getPartialPrintsTemplate(printSamples[i], ref partial_T_middleR, (i + 1));
                                    getSample(printSamples[i], ref S_middleR, (i + 1));
                                    bitmap = null;
                                    Convertor.ConvertToPicture(printSamples[i], ref bitmap);
                                    fingerprint = new Fingerprint();
                                    fingerprint.BitmapImage = bitmap;
                                    //st.Start();
                                    AFIS.Extract(fingerprint);
                                    if (fingerprint.Template != null)
                                        partial_T_middleR = fingerprint.Template;
                                    else
                                        partial_T_middleR = null;
                                    break;
                                case 4:
                                    getTemplate(printTemplates[i], ref T_ringR, (i + 1));
                                    //getPartialPrintsTemplate(printSamples[i], ref partial_T_ringR, (i + 1));
                                    getSample(printSamples[i], ref S_ringR, (i + 1));
                                    bitmap = null;
                                    Convertor.ConvertToPicture(printSamples[i], ref bitmap);
                                    fingerprint = new Fingerprint();
                                    fingerprint.BitmapImage = bitmap;
                                    //st.Start();
                                    AFIS.Extract(fingerprint);
                                    if (fingerprint.Template != null)
                                        partial_T_ringR = fingerprint.Template;
                                    else
                                        partial_T_ringR = null;
                                    break;
                                case 5:
                                    getTemplate(printTemplates[i], ref T_smallR, (i + 1));
                                    //getPartialPrintsTemplate(printSamples[i], ref partial_T_smallR, (i + 1));
                                    getSample(printSamples[i], ref S_smallR, (i + 1));
                                    bitmap = null;
                                    Convertor.ConvertToPicture(printSamples[i], ref bitmap);
                                    fingerprint = new Fingerprint();
                                    fingerprint.BitmapImage = bitmap;
                                    //st.Start();
                                    AFIS.Extract(fingerprint);
                                    if (fingerprint.Template != null)
                                        partial_T_smallR = fingerprint.Template;
                                    else
                                        partial_T_smallR = null;
                                    break;
                                case 6:
                                    getTemplate(printTemplates[i], ref T_thumbL, (i + 1));
                                    //getPartialPrintsTemplate(printSamples[i], ref partial_T_thumbL, (i + 1));
                                    getSample(printSamples[i], ref S_thumbL, (i + 1));
                                    bitmap = null;
                                    Convertor.ConvertToPicture(printSamples[i], ref bitmap);
                                    fingerprint = new Fingerprint();
                                    fingerprint.BitmapImage = bitmap;
                                    //st.Start();
                                    AFIS.Extract(fingerprint);
                                    if (fingerprint.Template != null)
                                        partial_T_thumbL = fingerprint.Template;
                                    else
                                        partial_T_thumbL = null;
                                    break;
                                case 7:
                                    getTemplate(printTemplates[i], ref T_indexL, (i + 1));
                                    //getPartialPrintsTemplate(printSamples[i], ref partial_T_indexL, (i + 1));
                                    getSample(printSamples[i], ref S_indexL, (i + 1));
                                    bitmap = null;
                                    Convertor.ConvertToPicture(printSamples[i], ref bitmap);
                                    fingerprint = new Fingerprint();
                                    fingerprint.BitmapImage = bitmap;
                                    //st.Start();
                                    AFIS.Extract(fingerprint);
                                    if (fingerprint.Template != null)
                                        partial_T_indexL = fingerprint.Template;
                                    else
                                        partial_T_indexL = null;
                                    break;
                                case 8:
                                    getTemplate(printTemplates[i], ref T_middleL, (i + 1));
                                    //getPartialPrintsTemplate(printSamples[i], ref partial_T_middleL, (i + 1));
                                    getSample(printSamples[i], ref S_middleL, (i + 1));
                                    bitmap = null;
                                    Convertor.ConvertToPicture(printSamples[i], ref bitmap);
                                    fingerprint = new Fingerprint();
                                    fingerprint.BitmapImage = bitmap;
                                    //st.Start();
                                    AFIS.Extract(fingerprint);
                                    if (fingerprint.Template != null)
                                        partial_T_middleL = fingerprint.Template;
                                    else
                                        partial_T_middleL = null;
                                    break;
                                case 9:
                                    getTemplate(printTemplates[i], ref T_ringL, (i + 1));
                                    //getPartialPrintsTemplate(printSamples[i], ref partial_T_ringL, (i + 1));
                                    getSample(printSamples[i], ref S_ringL, (i + 1));
                                    bitmap = null;
                                    Convertor.ConvertToPicture(printSamples[i], ref bitmap);
                                    fingerprint = new Fingerprint();
                                    fingerprint.BitmapImage = bitmap;
                                    //st.Start();
                                    AFIS.Extract(fingerprint);
                                    if (fingerprint.Template != null)
                                        partial_T_ringL = fingerprint.Template;
                                    else
                                        partial_T_ringL = null;
                                    break;
                                case 10:
                                    getTemplate(printTemplates[i], ref T_smallL, (i + 1));
                                    //getPartialPrintsTemplate(printSamples[i], ref partial_T_smallL, (i + 1));
                                    getSample(printSamples[i], ref S_smallL, (i + 1));
                                    bitmap = null;
                                    Convertor.ConvertToPicture(printSamples[i], ref bitmap);
                                    fingerprint = new Fingerprint();
                                    fingerprint.BitmapImage = bitmap;
                                    //st.Start();
                                    AFIS.Extract(fingerprint);
                                    if (fingerprint.Template != null)
                                        partial_T_smallL = fingerprint.Template;
                                    else
                                        partial_T_smallL = null;
                                    break;
                            }
                        }
                    }
		}
Posted
Updated 4-Apr-13 10:41am
v2
Comments
Sergey Alexandrovich Kryukov 3-Apr-13 18:31pm    
You should tag your application type or UI library you are using (WPF, Forms, most likely).
—SA

You should not "handle freezing", it makes no sense. You need to perform all time-consuming operations in a separate thread(s). And the thread would need to interact with the UI thread. How to do it?

You cannot call anything related to UI from non-UI thread. Instead, you need to use the method Invoke or BeginInvoke of System.Windows.Threading.Dispatcher (for both Forms or WPF) or System.Windows.Forms.Control (Forms only).

You will find detailed explanation of how it works and code samples in my past answers:
Control.Invoke() vs. Control.BeginInvoke()[^],
Problem with Treeview Scanner And MD5[^].

See also more references on threading:
How to get a keydown event to operate on a different thread in vb.net[^],
Control events not firing after enable disable + multithreading[^].

—SA
 
Share this answer
 
Comments
Emejulu JVT 3-Apr-13 19:02pm    
thats exactly what i did in the backgroundworker_DoWork... class. I used invoke, but it still freezes the apps
Sergey Alexandrovich Kryukov 3-Apr-13 19:11pm    
What can I say? You did it wrong. There are different obstacles showing up when you do it wrong, such as deadlocks, race conditions (which don't freeze anything by themselves but randomly go into troubles), or just excessive synchronization which lets things happen but kills parallelism... If you could make a short but complete code sample to reproduce the problem, we could discuss it...
—SA
Dont Change the app to handle the processing.. The user has to wait for the evaluation of the fingerprint.. if your using the background handler put a animated gif up "Wait".. Otherwise check your code if using vs2012.. try the "Analyse code" and see if there is anything specifically hanging the app.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900