Reputation: 4081
We all know that whenever we request for a web page or hit a button(on a web page) then a new thread is created on the server to give us the required result.
Now, what I need is the thread which is serving a this request. I need to set the Apartment state of this serving thread to STA, for working with Watin API.
What I am doing is I am opening a new IE browser window on the server, the code for that I have written inside the button click event. Now Watin requires the apartment state to be STa.
Thanks.
Upvotes: 0
Views: 1902
Reputation: 3311
You shouldn't need to know anything about the server as WatiN is client-side automation.
Follow the directions here for your particular scenario: http://watin.org/documentation/sta-apartmentstate/
Upvotes: 0
Reputation: 36092
Actually, a new thread is not created to handle every web request. The request is handled on a thread taken from a shared pool of available threads. Creating a new thread from scratch is pretty expensive, sometimes taking longer than the task you want to perform on the thread.
You can get the current executing thread using System.Threading.Thread.CurrentThread.
Since your request is executing on a shared thread managed by the IIS server, it's probably not a good idea to change the apartment model of the thread.
Upvotes: 1