can someone help me wit this, why does my form becomes unresponsive when i execute this code:
private Thread trd;
private int y = 0;
delegate void MyDelegate(bool show);
private void button1_Click(object sender, EventArgs e)
{
trd = new Thread(new ThreadStart(this.ThreadTask));
trd.IsBackground = true;
trd.Start();
}
private void ShowProgressBar(bool show)
{
progressBar1.Visible = show;
int x = 0;
int stp;
int newval;
Random rnd = new Random();
while (true)
{
stp = this.progressBar1.Step * rnd.Next(-1, 2);
newval = this.progressBar1.Value + stp;
if (newval > this.progressBar1.Maximum)
newval = this.progressBar1.Maximum;
else if (newval < this.progressBar1.Minimum)
newval = this.progressBar1.Minimum;
this.progressBar1.Value = newval;
Thread.Sleep(100);
}
}
private void ThreadTask()
{
Invoke(new MyDelegate(ShowProgressBar), true);
}