Click here to Skip to main content
15,888,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wanted to call a function Recurse(LPCTSTR pstr) to scan files and at the same time wanted to do another task but when I'm clicking on Resume Button I have to wait Until whole scanning finished.

what should I do...

What I have tried:

void CPracticePictureControlandlabelsDlg::OnBnClickedResume()
{
	// TODO: Add your control notification handler code here
	Recurse(L"E:\\");
}


void CPracticePictureControlandlabelsDlg::Recurse(LPCTSTR pstr)
{
	m_picProgressGif.Draw();
	m_picMyimg.Draw();
   CFileFind finder;

   // build a string with wildcards
   CString strWildcard(pstr);
   strWildcard += _T("\\*.*");

   // start working for files
   BOOL bWorking = finder.FindFile(strWildcard);

   while (bWorking)
   {
      bWorking = finder.FindNextFile();

      // skip . and .. files; otherwise, we'd
      // recur infinitely!

      if (finder.IsDots())
         continue;

      // if it's a directory, recursively search it

      if (finder.IsDirectory())
      {
         CString str = finder.GetFilePath();			 
		 m_lblMessage.SetText(str);
		 
         Recurse(str);
      }
   }

   finder.Close();
}
Posted
Updated 6-Mar-17 1:02am

1 solution

You have to create a worker thread that performs the operation in the background.

But MFC is not thread safe so that you have to implement some kind of signaling like sending user defined Windows messages if you want to update GUI elements from the thread.

You might also need to track the state of the thread (running or exited) to avoid starting it again / another one and signal your main thread when the worker thread is terminating after the work is done. If the worker thread might run for a longer time it might be also necessary to implement a kill mechanism (called upon a Stop button press or when the application is terminated).

Some readings:
Multithreading with C++ and MFC[^]
Using Worker Threads[^]
Simple Thread: Part I[^]
 
Share this answer
 
Comments
Jochen Arndt 15-Apr-17 3:18am    
Sorry, but I have never used biometric devices.
I suggest to check the device documentation and if the manufacturer has a support forum.

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