Follow us on twitter

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.


    • CommentAuthordark2025
    • CommentTimeOct 21st 2009
     
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Threading;

    namespace WindowsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void button1_Click(object sender, EventArgs e)
            {
                ThreadStart StartThreads = new ThreadStart(CreateTestThread);
                Thread[] TestThreads = new Thread[7];
                for (int x = 0; x < 7; ++x)
                {
                    TestThreads[x] = new Thread(CreateTestThread);
                    TestThreads[x].SetApartmentState(ApartmentState.STA);
                    TestThreads[x].Name = x.ToString();
                    TestThreads[x].Start();
                }
            }

            private void CreateTestThread()
            {
                string ThreadNumber = Thread.CurrentThread.Name;
                WebBrowser ThreadedBrowser = new WebBrowser();
                ThreadedBrowser.Dock = System.Windows.Forms.DockStyle.Fill;
                ThreadedBrowser.DocumentCompleted += new System.Windows.Forms.WebBrowserDocumentCompletedEventHandler(this.PageLoaded);
                this.Invoke(new MethodInvoker(delegate() { this.Controls.Add(ThreadedBrowser); }));
                ThreadedBrowser.Navigate(new Uri("http://www.warez-bb.org"));
                //All my threads exit here
            }

            private void PageLoaded(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
                MessageBox.Show(Thread.CurrentThread.Name);
            }
        }
    }

    Hi again everyone, Im having a problem with the code above . Im creating controls dynamically and on different threads which works but despite adding an event handler the threads all exit without waiting for its web control to finish loading.

    Is there any way to stop exiting after private void CreateTestThread() ?

  1.  

    It quits because theres nothing else left to do. Try adding a while loop to loop until the page is loaded


Add your comments