c# - Clipboard.SetFileDropList doesn't work fine -
i have lines of code in method change clipboard content:
system.collections.specialized.stringcollection stc = new system.collections.specialized.stringcollection(); stc.addrange(system.io.directory.getdirectories(temppath)); stc.addrange(system.io.directory.getfiles(temppath)); clipboard.clear(); clipboard.setfiledroplist(stc);
when go in debug mode , put breakpoint method works fine , clipboard updated, content in clipboard not available when method ends (my folder not destroyed obviously).
some ideas?
edit:
if break execution message box before exit works, otherwise not. tried setdata object, same.
edit 2:
the filedroplist seems clipboard paste disabled in system.
edit 3:
i think i've found problem: reason can because app takes ownership of clipboard , not release until closed, not allow external usage of actual content. way invoke win32 dll.
the clipboard class can used in threads set single thread apartment (sta) mode. options are
- mark main method stathreadattribute attribute.
or
- create sta thread application , use clipboard
example code option #2
system.collections.specialized.stringcollection stc = new system.collections.specialized.stringcollection(); stc.addrange(system.io.directory.getdirectories(temppath)); stc.addrange(system.io.directory.getfiles(temppath)); //clipboard.clear(); //no need call this. //>call sta thread thread t = new thread(() => { clipboard.setfiledroplist(stc); }); t.setapartmentstate(apartmentstate.sta); t.start();
Comments
Post a Comment