Windows Develop Bookmark and Share   
 index > Windows Forms Designer > OLE calling and STAThread
 

OLE calling and STAThread

I have an custom control, defined in class library that dynamicly constructs context menu, and makes "Paste" item visible only if there is any text at Clipboard (..GetDataPresent(..)).

Main function is attributted as STAThread, but when void of Menu forming is calling it cause following exception:

"You must set STA threading model for making OLE calls, check that your "Main" function is marked as STAThread"
Call stack shows that this exception was raised at checking clipboard part of void

For additional:
1. Calling Clipboard methods from menu (Copy, etc) does not raise any exceptions
2. The form with this control worked properly in test application (that simple loads this form), no any problem with STA and OLE (in target application form hosted by an object that included into Window Service and called remotly by TCP Channel)
MigrationUser 1  Tuesday, May 27, 2003 10:01 PM
I wonder if OLEInitialize isn't getting called for some reason...  So, the Main method of the application in which this control is being hosted is marked with STAThread?
MigrationUser 1  Tuesday, June 03, 2003 4:46 PM
Of course, all "Mains" marked as STA
MigrationUser 1  Friday, June 06, 2003 2:08 AM
At what stage in the execution of the program are you building the menu?  Is this in, for example, the Popup event?
MigrationUser 1  Friday, June 06, 2003 10:14 AM
Yes it is, the Popup event
MigrationUser 1  Monday, June 09, 2003 10:32 PM
Have a look at what threading state Application.OleRequred() returns you....  

MigrationUser 1  Wednesday, June 11, 2003 12:15 PM

You can use google to search for other answers

Custom Search

More Threads

• richtext box vertical scroll bar event
• Disable event autogenerate on control double click?
• Snaplines in CustomDesigner
• A Split Textbox
• How to use pics in Controls
• Could not load file or assembly
• Problem after hiding an owned form
• Windows Form Designer and the 'Do not modify... warning
• Displaying icons in the property grid against each item's label on the left.
• About 64 bit environment appilcations?