[英]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 Method
}
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. 此GetData方法在该类上没有正文。 How can I call any method of my project in place of GetData. 如何调用我的项目的任何方法来代替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. 不是很多信息,但我可能会将GetData放入委托中,因此您可以在创建类实例时将其替换为所需的内容。 Something like: ' public class Class1 { public delegate void GetDataDelegate(string url); 类似于:'public class Class1 {public delegate void GetDataDelegate(string url); private event GetDataDelegate GetData; 私有事件GetDataDelegate GetData;
public Class1(GetDataDelegate getData)
{
GetData += getData;
}
//blah blah blah
}
' “
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.