Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C# 

Get this error when using background worker

ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment.'

Code
string account = listBox1.Items[i].ToString();
                BackgroundWorker backgroundWorker;
                backgroundWorker = new BackgroundWorker();
                backgroundWorker.DoWork += new DoWorkEventHandler(CheckSpotify);
                backgroundWorker.RunWorkerAsync(account);
                Thread.Sleep(2000);


 private void CheckSpotify(object sender, DoWorkEventArgs e) {

           

            string account = e.Argument.ToString();

            string[] Account = account.Split(':');
            string user = Account[0].ToString();
            string pass = Account[1].ToString();
            WebBrowser w1 = new WebBrowser();

            

            w1.Navigate("https://accounts.spotify.com/en-GB/login?continue=https:%2F%2Fwww.spotify.com%2Fuk%2Faccount%2Foverview%2F");
            HtmlDocument doc = this.w1.Document;
            HtmlElement username = doc.GetElementById("login-username");
            HtmlElement password = doc.GetElementById("login-password");
            username.SetAttribute("value", user );
            password.SetAttribute("value", pass);
            username.Focus();
            SendKeys.SendWait("~");

        }
Example:
PHP Code

<?php 
Thread _thread 
= new Thread(()=> Foo());
_thread.SetApartmentState(ApartmentState.STA);
_thread.Start();

void Foo()
{ 
 
    // Insert code.
} 

Link: MSDN
You're approaching the account checking in a very inefficient way. I think you should forget about this problem and move onto sending POST requests manually.
[Image: Syr3DlV.png]
Background threads are running on MTA threads while you need an STA thread for that component.
Getting Started: C/C++
[C/C++/.NET/x86 ASM - Automation Programmer]


Possibly Related Threads...
Thread / Author Replies Views Last Post
by THOR TECHAug 18, 2024 06:37 PM 4 193 Aug 18, 2024 06:37 PM
Last Post: Lookdadon
[.NET] by FhackJan 10, 2018 04:36 AM 4 160 Jan 10, 2018 04:36 AM
Last Post: Fhack
[.NET] by NinjaMay 12, 2017 09:50 AM 6 402 May 12, 2017 09:50 AM
Last Post: Ninja