找到你要的答案

Q:Using call back function between two project

Q:使用两个项目之间的回调函数

I have a console application which continuously receives messages and saves those messages to a database. And I have another project which has a method that takes a message and checks if this message contains certain information. Now I want use a delegate to create a pointer for the check method and pass this pointer to the console application. Both projects are in the same solution. How can I do that?

我有一个控制台应用程序,它不断地接收消息并将这些消息保存到数据库中。我有另一个项目,它有一个方法,它需要一个消息,检查这个消息是否包含某些信息。现在,我想使用委托创建一个指针的检查方法,并通过此指针控制台应用程序。这两个项目都在同一解决方案。我该怎么做?

answer1: 回答1:

You probably can't, because it sounds like from your description that the two programs are running in separate processes. Perhaps you could watch for new messages to your database, or set up a pipe between the two. In order to use a delegate your programs would need to be in the same process space.

If I have mis-read your post and one project is an exe and the other a dependent dll, then you can do what you are thinking. You can search for "C# event delegate examples". If you have a problem post some example code.

您可能不能,因为这听起来像从您的描述,这两个程序正在运行在单独的进程。也许您可以观看新的消息到您的数据库,或建立一个管道之间的两个。为了使用委托,您的程序需要在同一进程空间中。

如果我错看了你的帖子,其中一个项目是一个EXE和其他相关的DLL,那么你可以做你所想的。你可以搜索“C #事件委托实例”。如果你有问题的一些例子代码。

c#  callback  delegates