STAThread error on windows grid

  • Thread starter Thread starter Vishy
  • Start date Start date
V

Vishy

Hello guys

I'm getting following error "The current thread must set to Single
Thread Apartment (STA) mode before OLE calls can be made. Ensure that
your Main function has STAThreadAttribute marked on it" on CTRL+C on
grid cell; I'm opening this form from a .net dll; so there's no Main()
method;

How can I fix this?

Thanks

Vishy
 
Hi Vishy,

You should explicitly change the threading model to single-thread apartment
(STA) before creating your form. There are two ways to do this 1) decorate
your Main method with the STAThreadAttribute attribute 2) use the following
code System.Threading.Thread.CurrentThread.ApartmentState =
System.Threading.ApartmentState.STA;

See here for additional information
http://msdn.microsoft.com/library/d...estar/managed_ovw/tbconinkcontrolconcepts.asp

Best regards,
Paul Gielens

Visit my blog @ http://weblogs.asp.net/pgielens/
###
 
Thanks Paul for reply

But I don't have a Main() method in my form; or application; where can
I add this code?
I tried adding it to form_load() but it didn't work


Vishy
 
Hello,
I'm opening this form from a .net dll; so there's no Main() method;

I think the calling application has to specify STA then.
If it doesn't use a GUI, you might also consider creating a new thread in
the library.


Regards,
Michael
 
Thanks Michael

I fixed the problem; patch was strange; i derived DataGrid into
another class; handled ProcessDialogKey event and it worked; no more
STAThread exception
I don't know the implications of this fix;but it worked

Vishal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top