Q: DirectoryInfo.GetFiles

  • Thread starter Thread starter Martin Arvidsson, Visual Systems AB
  • Start date Start date
M

Martin Arvidsson, Visual Systems AB

Hi!

Is there any way to abort the process of GetFiles method?

I have a Method that will scan thousands of files and directories. But the
user will be able to abort this process, which i fully understand.

I do use a BackgroundWorker to be able to cancel to process, but since the
GetFiles don't ever leave the method until all the files has been found that
i told it to do, i cant process the BackgroundWorker.Cancelpending.

Any ideas?

Regards
Martin
 
Martin,

You could create a thread yourself and call GetFiles on that thread, and
then marshal the file information back to the UI thread. If the user aborts
the process, then you can just call Abort on the thread. It's not going to
abort immediately, as it will wait for the calls to the P/Invoke layer to
complete, but once the code exits back to managed code, the
ThreadAbortException will be thrown and the thread will stop processing.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top