how to call any method of Project from classlibrary?
I have Class Library Where a class of multithreading Of Producer and consumer based.
private void WorkDeQueue()
{
while (true)
{
string Url = null;
lock (locker)
{
if (queueList.Count > 0)
{
Url = queueList.Dequeue();
/* return if a null is found in the queue */
if (Url == null) return;
}
}
if (Url != null)
{
/* if a job was found then process it */
GetData(Url); //This Is a Meth开发者_运维百科od
}
else
{
/* if a job was not found (meaning list is empty) then
* wait till something is added to it*/
wh.WaitOne();
}
}
}
This GetData method has no body on that class. How can I call any method of my project in place of GetData.
I tried with factory Pattern and also with reflection, but both didn't work for me. So plz tell me how I can call any method of my project from here.
Not really a lot of info to go on, but I'd probably make GetData in to a delegate so you can just replace it with whatever is needed when you create the class instance. Something like: ' public class Class1 { public delegate void GetDataDelegate(string url); private event GetDataDelegate GetData;
public Class1(GetDataDelegate getData)
{
GetData += getData;
}
//blah blah blah
}
'
精彩评论