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

  1. mark main method stathreadattribute attribute.

or

  1. 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

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -