I am trying to drag an item out into the explorer.
The item should result in a file download, so I've used an example I've found on the web to download the file using a CustomDataObject
that calls an event when he actually needs the stream, and then my application does the heavy lifting and performs the download.
It's been working just fine in a similar Clipboard operation.
The actual file download also causes some UI changes in my application. Mostly a "working" icon changing on the form, and also a popup balloon in case of an error.
In the clipboard operation I just used InvokeRequired
and BeginInvoke
when needed, to make sure those UI changes happen on the main thread. In the drag operation, the UI thread is waiting for the return from the DoDragDrop
, while the event being raised by the CustomDataObject
is being called on a different thread. When I try to call BeginInvoke
or Invoke
the UI thread is still waiting, and I can't finish the drop.
Is there some sample, or a recommended best practice, on how to allow cross-application drag n drop, while accessing the UI of the source application?
UPDATE
here is the original CodeProject article with the DataObjectEx
I modified for my own use. I just changed the GetFileContents
method to call a virtual method which returns a Stream
containing the file data, inherited from the class, and overridden that virtual method to get the file from the web.
The problem arose when I wanted to change stuff in the UI, while getting the file. As I said earlier - the main UI thread is still "stuck" at the DoDragDrop
method call, so I can't invoke it on time to do the UI changes needed by the worker thread before and after downloading the file.