4

I have a simple example of a winforms application where i choose a directory in a directory chooser and click a button to loop through the directory and copy each file in the directory into another directory.

i want to do the file copy on a background thread to avoid locking the GUI.

i am looking for the simplest solution to:

  1. Create the background thread
  2. Pass the source and destinations in
  3. Get a callback on progress so i can show a progress bar on the GUI thread

2 Answers 2

7

I would recommend using the BackgroundWorker class.

Example.

Sign up to request clarification or add additional context in comments.

Comments

2

In addition to the above answer, I'd add that the BackgroundWorker is ideal for this as it can give you progress updates too. Just make sure you prevent reentry - that is you need to prevent the situation where the user could start the background worker again before it has completed.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.