转移同一台计算机上的.NET应用程序之间进行大数据一台、机上、应用程序、数据

2023-09-02 01:56:32 作者:亏欠

我有一个在同一台机器上运行两个.NET应用程序。 第一个应用是引擎。它建立图像 - 图像的大小为4M左右。 第二个应用是浏览器。它显示了其引擎发送图像。 该发动机将图像每隔10-15秒。

I have two .net applications that run on the same machine. The first application is the 'Engine'. It builds images - image's size is about 4M. The second applications is the 'Viewer'. It shows the images which the 'Engine' sends. The engine sends images every 10-15 seconds.

我的问题是什么是从发动机到观察者传递图像的韧皮方式。 目前,我使用的文件系统这一点。发动机写入图像文件系统文件夹和观众获得使用FileSystemWatcher的这个文件。

My question is what is the bast way to pass the images from the engine to the viewer. Currently, I'm using FileSystem for this. The Engine writes the image to file system folder and the viewer getting this file using FileSystemWatcher.

时的这种做法可以吗?那是可靠的?

Is that approach ok? Is that reliable?

推荐答案

还有就是不错的选择号:

There is number of good options:

在消息队列 在命名管道(直接) 内存映射文件 在WCF命名管道或MSMQ

任何那些超过速度不够快,所以我建议最容易实现的。

Any of those is more than fast enough so I would suggest easiest to implement.

消息队列(MSMQ)在我看来是最简单的使用,为您提供了对象转移(而不是流),并为您提供了可选的运输持久性(有用的情况下发送者或接收者没有运行)。所有这是真实的WCF通过MSMQ但WCF意味着更多的开销,复杂性和配置并没有额外的(在这种情况下)值

Message Queue (MSMQ) in my opinion is simplest to use, gives you object transfer (as opposed to streams) and gives you optional transport persistence (useful in case sender or receiver is not running). All this is true for WCF over MSMQ but WCF means more overhead, complexity and configuration involved and no additional (in this case) value.

发送这样的:

MessageQueue queue = new MessageQueue(".\private$\ImagesQueue");
Message msg = new Message
{
    Formatter = new BinaryMessageFormatter(),
    Body = myImage,
    Label = "Image"
};
queue.Send(msg);

收件人:

MessageQueue queue = new MessageQueue(".\private$\ImagesQueue");
msg = queue.Receive(TimeSpan.FromMilliseconds(100));
if (msg != null)
{
    msg.Formatter = new BinaryMessageFormatter();
    myImage = (MyImage)msg.Body;
}

队列使用前需要进行创建。你可以这样做,当你的应用程序启动

Queue needs to be created before use. You can do that when your application starts

在类中有这样的:

private const string queueName = ".\private$\ImagesQueue";

和在应用程序初始化/启动要确保你有你的队列:

And in application initialization/startup make sure you have your queue:

if (!MessageQueue.Exists(queueName)
{
    MessageQueue myQueue = MessageQueue.Create(queueName);
}

通过这种队列机制,发动机不必等待浏览器来完成。这将大大提高感知性能,因为您可以生成一个图像(实际数人),而previous一个仍在观察。不是那么容易实现与内存映射文件。

With this queue mechanism, Engine does not have to wait for the Viewer to complete. This would much improve perceived performance because you can generate next image (actually number of them) while previous one is still being viewed. Not so easy to achieve with memory mapped files.

MSMQ是一个标准的Windows组件,但需要在Windows功能被激活。

MSMQ is a standard Windows component but needs to be enabled in Windows Features.

 
精彩推荐