How to call any Project method from classlibrary?

I have a class library where the multithreading class is producer and consumer.

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 does not have a body in this class. As I can name any method of my project instead of GetData.

I tried using factory Pattern as well as reflection, but both did not work for me. So plz tell me how I can name any method of my project here.

+4
source share
1 answer

There is not much information to continue, but I would probably include GetData in the delegate so that you can simply replace it with what you need when you instantiate the class. Something like: 'public class Class1 {public delegate void GetDataDelegate (string url); private event GetDataDelegate GetData;

  public Class1(GetDataDelegate getData) { GetData += getData; } //blah blah blah } 

+1
source

Source: https://habr.com/ru/post/1304615/


All Articles