Using a library that requires STAThread in WPF with async
I'm using ESAPI, a library to access data from a medical database environment. To use it, the Main method needs to be in "single-threaded apartment" to access COM stuff. I want to include this in a WPF app, like a Entity Framework data context where I access it to search patients and apply search filters.
I'm struggling to find a way to do this. Should I have the "data context" like a class library and call it whenever I have a unit of work? Itd require a user to enter a password each time a search was done. I'd prefer a way to open the library and keep it open for quick searches.
Page 29 on here: https://www.google.com/url?sa=t&source=web&rct=j&opi=89978449&url=https://www.freelists.org/archives/vabene/01-2017/pdfutgYzAV_SF.pdf&ved=2ahUKEwj0js6SnreHAxU4DjQIHSw0D3wQFnoECCoQAQ&usg=AOvVaw0rPfu9Yo4WWWIvouNOc3so
2 Replies
Would setting the ESAPI app as a background worker solve this?
Or am I thinking of background service?
I believe the main thread is already STA in WPF apps. I’m unsure how to do that for background threads though.