0

マルチスレッドアプリを作成し、例外が発生しました これCross-thread operation not valid: Control 'richTextBox2' accessed from a thread other than the thread it was created on. が私のコードです:

    Thread[] thr;
    static object locker = new object();
    string titles_path, routes_path, mamas_path, descriptions_path, site_urls_path;
    private void button1_Click(object sender, EventArgs e)
    {
        decimal value = numericUpDown1.Value;
        int i = 0;
        int j = (int)(value);
        thr = new Thread[j];
        for (; i < j; i++)
        {
            thr[i] = new Thread(new ThreadStart(go));
            thr[i].IsBackground = true;
            thr[i].Start();
        }
    }

    public void go()
    {
        while (true)
        {
            string mama = "";
            string ua = HttpHelper.ChromeUserAgent();
            string[] site_url = new string[20];
            lock (locker)
            {
                if (mamas.Count == 0)
                {
                    break;
                }
                else
                    mama = mamas.Dequeue();
            }

            Sed sed = new Sed(mama, ua);
            string auth = sed.Auth(textBox1.Text.Split(':')[0], textBox1.Text.Split(':')[1].Trim());
            if (auth == "Login")
            {
                lock (locker)
                {
                    for (int runs = 0; runs < 20; runs++)
                    {
                        if (site_urls.Count == 0)
                        {
                            break;
                        }
                        else
                            site_url[runs] = site_urls.Dequeue().Replace("http://", "");
                    }
                }
                string add_domains = sed.add_domains(site_url);
                if (add_domains == "Added")
                {
                    for (int runs = 0; runs < 20; runs++)
                    {
                        string dorway = site_url[runs];
                        if (string.IsNullOrEmpty(dorway))
                            break;
                        string title = rand_title();
                        string description = rand_description();
                        string route = rand_route();
                        string[] rtfLines = new string[richTextBox2.Lines.Length];
                        var num = xNet.Rand.Next(0, richTextBox2.Lines.Length);
                        string template = rtfLines[num];

                        string set_config = sed.set_config(dorway, title, description, route, template);
                        if (set_config == "Saved")

それを機能させるために助けてください/

4

0 に答える 0