Searching files in step-by-step mode RRS feed

  • Question

  • Hello everybody,
    I would like to get files from big directories. In that context, if the search takes too long (i.e. remote search), I would like to be able to interrupt it (I'am a little bit afraid that Directory.GetFiles() takes too long before returning control to my code...)
    When I was working with the Win32 API and MFC, I used some FindFirstFile/FindNextFile loop that I could stop on user action. I would like to know if the .NET class library provides such a solution.
    Any hint ? Is there a way to "kill" the execution of a method like "Directory.GetFiles()" ?

    Tuesday, May 2, 2006 9:28 AM

All replies

  • Do the file search on a separate thread, such as

    Thread t = new Thread(new ThreadStart(FindFiles()));

    t.IsBackground = true;


    in the client code.

    private void FindFiles()


      //do long running operation here


    This has two advantages-

    1/Keeps the UI responsive

    2/Allows you to abort the thread at any time by saying t.Abort();

    Hope this is useful.

    Tuesday, May 2, 2006 10:11 AM
  • Thanks. I will do this way.
    Tuesday, May 2, 2006 12:48 PM