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
Post a Comment