'CallBack'에 해당되는 글 1건
using System;
using SystemThreading;
using System.Windows.Forms;
namespace WindowsApplication1
{
public class Counter
{
private Label LabeltoUpdate;
private int MaxCount;
privateCallBackCallBackMethod;
public Counter(Label l,int max, CallBack cb)
{
LabeltoUpdate = l;
MaxCount = max;
CallBackMethod = cb;
}
public void BeginProcessing()
{
int i;
for(i=1;i < MaxCount; i )
{
LabeltoUpdate.Text = i.ToString();
LabeltoUpdate.Refresh();
}
//Tell the main thread we have completed
CallBackMethod(i,Thread.CurrentThread.Name);
}
}
}
using System.Threading;
private void button1_Click(object sender, System.EventArgs e)
{
Counter c1 = new Counter(label1,3000,new CallBack(ThreadCompleted));
Counter c2 = new Counter(label2,1500,new CallBack(ThreadCompleted));
Thread t1 = new Thread(newThreadStart(c1.BeginProcessing));
Thread t2 = new Thread(new ThreadStart(c2.BeginProcessing));
t1.Name = "Counter Thread 1";
t2.Name = "Counter Thread 2";
t1.Start();
t2.Start();
}
private void ThreadCompleted(int intTotal,string strName)
{
MessageBox.Show("Thread " strName
" has completed at " intTotal.ToString());
}
using SystemThreading;
using System.Windows.Forms;
namespace WindowsApplication1
{
public class Counter
{
private Label LabeltoUpdate;
private int MaxCount;
privateCallBackCallBackMethod;
public Counter(Label l,int max, CallBack cb)
{
LabeltoUpdate = l;
MaxCount = max;
CallBackMethod = cb;
}
public void BeginProcessing()
{
int i;
for(i=1;i < MaxCount; i )
{
LabeltoUpdate.Text = i.ToString();
LabeltoUpdate.Refresh();
}
//Tell the main thread we have completed
CallBackMethod(i,Thread.CurrentThread.Name);
}
}
}
using System.Threading;
private void button1_Click(object sender, System.EventArgs e)
{
Counter c1 = new Counter(label1,3000,new CallBack(ThreadCompleted));
Counter c2 = new Counter(label2,1500,new CallBack(ThreadCompleted));
Thread t1 = new Thread(newThreadStart(c1.BeginProcessing));
Thread t2 = new Thread(new ThreadStart(c2.BeginProcessing));
t1.Name = "Counter Thread 1";
t2.Name = "Counter Thread 2";
t1.Start();
t2.Start();
}
private void ThreadCompleted(int intTotal,string strName)
{
MessageBox.Show("Thread " strName
" has completed at " intTotal.ToString());
}

Prev

Rss Feed