8

I would like to have

  • one background thread which will copy the files through the SHFileOperation function, always only one SHFileOperation at the time (but I want it to be in the thread)
  • I need the UI output, so I need to use the FOF_SIMPLEPROGRESS flag and pass something to the Wnd member

I have two questions

  1. is it safe to call the SHFileOperation with FOF_SIMPLEPROGRESS flag (for user interaction) from the thread other than main ?
  2. if yes, what handle should I pass into the Wnd member ? I've tried the handle of the main form, but when e.g. the overwrite confirmation dialog pops up and you confirm it, the main form is sent to the background, what is really strange

Note: I have a queue for these operations, so only one SHFileOperation is performed at the time (after it's finished, the thread continues to the other action, what might be the next SHFileOperation)

Thanks a lot

Martin Reiner
  • 2,167
  • 2
  • 20
  • 34

1 Answers1

7
  1. It's perfectly safe to call SHFileOperation from a thread other than the main thread.
  2. I would pass 0 as the hwnd member. If you pass the handle of the main window then I expect that window will be disabled because SHFileOperation is a modal dialog. Since the file confirmation and progress dialogs are the top level UI for the background thread, you don't want any windows to be disabled when these modal dialogs show.
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Great to hear this. `Wnd` member set to 0 works perfectly. Thanks a lot! – Martin Reiner Feb 28 '12 at 15:17
  • Also, the documentation also mentions that using relative paths with SHFILEOPSTRUCT is NOT thread safe. So if your using this in a worker thread you must use absolute paths! – 8bitwide Sep 20 '12 at 21:32
  • @8bitwide Using relative paths is never thread safe. Not for any API call. That's because there's one working directory per process. – David Heffernan Sep 20 '12 at 21:33