问题
I got a problem. I'd like to drag'n drop a file from my Form to explorer/ the desktop.
The problem is that the file is online. Then it must be downloaded somewhere on the disk before being copied in the destination folder.
I created a shell extension (I think it's that, at any rate), who use a background worker to download the file, but of course, even with that, while the file is downloading, the drag and drop operation isn't over and the UI is freezing.
What I would like to do is just doing a drag and drop to explorer, which will launch a download and copy the file, without the UI freezing during the download.
So, what can I do ?
Could I get the destination path and do the copying myself ?
Could I launch the entire drag and drop operation in another thread ?
I searched for a while and couldn't find any clear answers.
回答1:
Make a complete logical separation of those two concerns: drag & drop versus the actual download/save of the file.
Handle the drag & drop operation in its entirety, and upon completion (typically in an OnDragDrop
method), start the download and save process. You'd likely want an indication of progress somewhere.
Attempting to do it all during the drag/drop operation seems doomed to fail. You will never know just how long the download might take, or if it will fail entirely. Handling any of that in the midst of a drag & drop seems bad.
回答2:
You can call a BackgroundWorkder inside the drop event handler.
来源:https://stackoverflow.com/questions/24013743/dragn-drop-with-file-downloading-c-sharp