简体   繁体   English

如何从classlibrary调用Project的任何方法?

[英]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.

相关问题 在.NET Core中从常规ClassLibrary调用方法? - Call method from regular ClassLibrary within .NET Core? 如何将ActionResult从ClassLibrary项目发送到另一个项目? - How send an ActionResult from a ClassLibrary project to another project? 我们可以从具有ClassLibrary项目的DLL文件返回DataTable吗? - Can we return a DataTable from DLL file having ClassLibrary Project? 如何从单独项目中的类调用方法 - how to call a method from class in seperate project 如何在ClassLibrary项目中实现System.Windows.Markup.MarkupExtension - How to implement System.Windows.Markup.MarkupExtension in a ClassLibrary-project 从ClassLibrary抛出异常 - Throw exception from ClassLibrary 如何从Web API项目调用通知项目中的post方法 - How to call the post method in notification project from web api project 如何使用 ConfigurationManager 将 Unity3d 中的连接字符串值传递到类库 - How to pass connectionstring value from Unity3d to a classlibrary with ConfigurationManager 如何在同一解决方案中从其他项目的dll中调用方法 - How to call a Method from an dll from an other project in the same solution 从.net项目中调用python项目中的方法 - Call a method in python project from a .net project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM