به این کد ها یک نگاه بنداز
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Sample s=new Sample((Invoker)Invoke);
s.Changed += new EventHandler<MyEventArgs>(s_Changed);
s.Start();
}
void s_Changed(object sender, MyEventArgs e)
{
//Your Statements
}
}
delegate object Invoker(Delegate D,params object[] args);
class MyEventArgs:EventArgs
{
public MyEventArgs(String result)
: base()
{
Result = result;
}
public string Result;
}
class Sample
{
Invoker _invoker;
Thread MyThread;
public Sample(Invoker invoker)
{
_invoker = invoker;
MyThread = new Thread(new ThreadStart(ThreadProc));
MyThread.IsBackground = true;
}
public void Start()
{
MyThread.Start();
}
void ThreadProc()
{
while (true)
{
if(Your Condition)
_invoker(Changed,new MyEventArgs("result"));
}
}
public event EventHandler<MyEventArgs> Changed;
}