Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I was just trying to print 100 numbers in two listboxes simultaneously using multithreading.I put the controls inside the update panel.And when i click on the button they print only 0.I am new in asp.net so kindly help me to fix this.My coding is shown below.

C#
protected void Button1_Click(object sender, EventArgs e)
    {
        try
        {
            Thread tid1 = new Thread(new ThreadStart(this.Thread1));
            Thread tid2 = new Thread(new ThreadStart(this.Thread2));

            tid1.Start();
            tid2.Start();
        }
        catch
        {
        }
    }
    public void Thread1()
    {
        try
        {
            for (int i = 0; i < 100; i++)
            {
                ListBox1.Items.Add(i.ToString());
                Thread.Sleep(10);
            }
        }
        catch (Exception ex)
        {
            Label1.Text = ex.Message;  
        }
    }
    private void Thread2()
        {
            try
            {
                for (int i = 0; i < 100; i++)
                {
                    ListBox2.Items.Add(i.ToString());
                    Thread.Sleep(10);
                    
                }
            }
            catch
            {
            }
        }
Posted
Comments
Timberbird 28-Sep-11 2:46am    
Do you mean you only have one zero in each ListBox upon button click, or there's a hundred of zeros? If it's only one zero, the reason may be that your main thread doesn't wait for tid1 and tid2 to finish their job

1 solution

refer that msdn for your problem

http://msdn.microsoft.com/en-us/magazine/cc164037.aspx[^]
 
Share this answer
 
Comments
sreenathpktr 28-Sep-11 2:00am    
I referred that...But that ain't helpful for solving my problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900