views:

59

answers:

2

Every time i want let the user to drag an control, i calling DoDragDrop of that control.

The drag & drop works fine, but i have problem with things around:

  1. DoDragDrop completely blocking the form, no timer events jumps, no paint messages handled.

  2. DoDragDrop blocking not only for the drag & drop operation, but until target program finishing with the drop event (I.E. explorer.exe's suck code). Depending on other program's code is sucks.

I thought to call DoDragDrop from a new thread.

tried this:

Thread dragThread = new Thread(() =>
{
    Form frm = new Form();
    frm.DoDragDrop("data", DragDropEffects.All);
});

dragThread.SetApartmentState(ApartmentState.STA);
dragThread.IsBackground = true;
dragThread.Start();

but it doesn't seems to work. I mean: when doing DoDragDrop from other thread like this, other controls within my program or other programs does not receiving drag&drop messages.

Any other solutions?

+1  A: 

You need to forget about using a thread, that's only going to deliver D+D notifications to the windows that were created on that thread. Which will not be your controls.

I can't do much with a "code is sucks" diagnostic. The DoDragDrop() call itself will indeed block until the mouse button is released. Another message loop, internal to COM code will take over and deliver the Windows messages. Timer and paint messages should be delivered as normal. A diagnostic is very hard to come by until you post some repro code.

Hans Passant
I suspect that what he might be talking about is that Explorer goes into a copy operation after the drop and causes his application UI to block while doing the copy. I know that it does that to WinRAR...
Timwi
There is a D+D protocol to allow the app to deliver the data in a late bound fashion. That's very hard to get going in a .NET program, certainly not "data".
Hans Passant
+1  A: 

You probably want the DoDragDrop to quit and do the job asynchronously.

Here is the answer.

modosansreves