MTA threads in WPF app (STA) not working?
DanS
✭✭
I recently ran into an issue calling certain functions in the ABB PC SDK from a WPF application. I will try and explain here.
WPF applications run as STAThread...this cannot be changed. About a month ago we had an issue when certain methods in the PC SDK were called from a NEW thread within the main STA thread. This was resolved by starting the thread as MTA:
Thread t = new Thread(new ParameterizedThreadStart(StartThread));
t.SetApartmentState(ApartmentState.MTA);
But something has changed suddenly (perhaps with a Microsoft update?) that prevents this from working. It's as if the MTA thread really is an STA thread, even though it tells you otherwise.
From what I can tell, the ONLY way I can get these certain functions in the PC SDK to work when run from a couple threads deep is to make sure the main application thread is MTA. If I start out as STA, I cannot create MTA threads that work with the PC SDK. If I start MTA everything works fine. If I start as MTA and create STA threads everything breaks again.
This is a problem for an application written in WPF that must be STA.
The functions I'm using that throw a generic System.Exeception with information are:
RapidDataType.GetComponents();
RapidData.ReadItem(i, j);
Any ideas on where to go from here?
Thanks,
Dan
0
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 316 IRC5
- 61 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 799 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings