i use of this code i thinking correct.
using System;
using System.Threading;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication37
{
public partial class Form1 : Form
{
public delegate void MyDelegate(int o);
MyDelegate myDelegate;
IAsyncResult j;
object a = new object();
void RunInThread(object u)
{
Monitor.Enter(this);
Thread.Sleep(100);
myDelegate = delegate(int b)
{
label1.Text = u.ToString();
Thread.Sleep(10);
};
j = this.BeginInvoke(myDelegate, (int)u);
Monitor.Exit(this);
}
void AddControl(int r)
{
}
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
int i = 0;
while (i < 100)
{
Thread.CurrentThread.Priority = ThreadPriority.Lowest;
Thread t = new Thread(new ParameterizedThreadStart(RunInThread));
t.Start(i);
Thread.Sleep(10);
Monitor.Enter(this);
EndInvoke(j);
label1.Invalidate();
i++;
Monitor.Exit(this);
}
}
}
}