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