c# - Getting STA error when try to open OpenFileDialog box in Excel addin project -


i have created excel addin project using visual studio insert data database.

problem i'm unable open file upload box in this.

getting following error.

my code

 [obsoleteattribute()]         [stathread]         private void save(progressbarform pbar)         {   openfiledialog openfiledialog1 = new openfiledialog();                         dialogresult result =  openfiledialog1.showdialog();                         if (result == dialogresult.ok)                         { //execute code 

i tried give attribute save method also giving me same error.

can me out.?

enter image description here

you need put [stathread] on main method, so:

[stathread] static void main() { 

alternatively, start new thread saving, along these lines:

var thread = new thread(mysavemethod); thread.setapartmentstate(apartmentstate.sta); thread.start(); thread.join(); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -