Wednesday, August 8, 2007

Thread and Delegate Issue

Run Thread with Parameters
----------------------------------------------
*** But it is only limited to 1 object...

Thread t = new Thread(new ParameterizedThreadStart(Run));
t.Start("an Object");

or using Thread Pool
-----
ThreadPool.QueueUserWorkItem(new WaitCallback(Run), "an Object");
-----



----------------------------------------------------------
*** Use Class method...
public
class UrlFetcher
{
string url

public UrlFetcher (string url)
{
this.url = url;
}

public void Fetch()
{
// use Any Attribute here
}
}

UrlFetcher fetcher = new UrlFetcher (myUrl);// Set All the input
new Thread (new ThreadStart (fetcher.Fetch)).Start();
-------------------------------
or Call Delegate Asyn

delegate void MyDel(object a, object b);

MyDel d = new MyDel(Fetch);
d.BeginInvoke(a,b,new AsyncCallback(AfterRun),"this is state");

====================================


===================================================
CALL DELEGATE Dynamically

void Force(Delegate method, object[] args)
{
method.DynamicInvoke(args)
}

No comments: