Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all
i want to show a picture box on login form as 'wait for login message' and to show WaitForloginPicturebox ,I run a new thread like below code:
C#
Thread t;
void ShowWaitImage()
{
    if (WaitForloginPicturebox .InvokeRequired)
    {
       this.WaitForloginPicturebox .Invoke(new MethodInvoker(ShowWaitImage));
    }
    else
    {
        this.pictureBox2.Visible = true;
    }
}
private void button1_Click(object sender, EventArgs e)
{
    t=new Thread(new ThreadStart(ShowWaitImage));
    t.Start();
    //...
}

but it doesn't show this.(Not Working)
Posted
Updated 7-Nov-13 2:27am
v2
Comments
MohsenSaleh 7-Nov-13 8:46am    
yes Not working
when i remove code after t.Strat() it work, but when I add code after t.Strat() not working

It won't work because you cannot touch the UI from a background thread, or any thread other than the UI (startup) thread. Put your login code in the background thread and keep the UI stuff on the startup thread.
 
Share this answer
 
I believe you are invoking the same method (ShowWaitImage) recursively. You never escape from the first part of the if...else
 
Share this answer
 
Comments
MohsenSaleh 7-Nov-13 9:16am    
how can escape from first part of if else?
i test it with a Boolean variable named call and change my code to :

if (WaitForloginPicturebox.InvokeRequired && call==false)
{
call = true;
this.WaitForloginPicturebox .Invoke(new MethodInvoker(ShowWaitImage));

}
else
{
this.WaitForloginPicturebox .Visible = true;

}

but don't work
Arnaldo P. Castaño 7-Nov-13 11:22am    
Make sure the variable is not getting reset to false when the method is call a second time.

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