c# - Issue with drag and drop -


i use following code drag , drop file c# winforms application. issue have dragdrop event handler takes while, , during time can't use window dragged file. how can fixed?

private void formmain_dragdrop(object sender, drageventargs e) {     string[] s = (string[])e.data.getdata(dataformats.filedrop, false);     // long operation }  private void formmain_dragenter(object sender, drageventargs e) { if (e.data.getdatapresent(dataformats.filedrop))     e.effect = dragdropeffects.all; else     e.effect = dragdropeffects.none; } 

you may use backgroundworker operation need in different thread following :

    backgroundworker bgw;      public form1()     {         initializecomponent();         bgw = new backgroundworker();         bgw.dowork += bgw_dowork;     }      private void form1_dragdrop(object sender, drageventargs e)     {         if (e.data.getdatapresent(dataformats.filedrop))         {             string[] s = (string[])e.data.getdata(dataformats.filedrop, false);             bgw.runworkerasync(s);         }      } 

also issue "cross thread operation", try use invoke method :

    void bgw_dowork(object sender, doworkeventargs e)     {         invoke(new action<object>((args) =>         {             string[] files = (string[])args;          }), e.argument);     } 

its better check if dropped items files using getdatapresent above.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -