I have a Winform with a BackgroundWorker. The BackgroundWorker, among other things, has to make an HTTP call to a page, fill out some data, submit the form, and retrieve the HTML that comes back after "clicking" the submit button. I've run into a number of roadblocks while doing this:
- Can't POST the data because the target webserver doesn't 405 support that method.
- Can't use a WebClient.UploadValues, again, because the webserver doesn't support POST.
- Can't use a WebBrowser control because BackgroundWorkers suck at COM Interop and an exception is thrown that says it must be in a STA thread (Single-Threaded Apartment)
- Can't run another seperate thread because the BW has to sit and wait for the result before it can continue (Can't, or at least I don't know a way to do this that won't crash)
- Can't change the ApartmentState of the thread because it's a BackgroundWorker and it throws if told to go to STA mode
What should I do to resolve this?
[Edit]: The app entrypoint is already tagged with the [STAThread] attribute.