简体   繁体   English

Windows服务和桌面应用程序之间的通信

[英]Communication between Windows Service and Desktop Application

I know that similar questions have been asked before, but even after all my Googling I'm still completely lost. 我知道之前已经提出了类似的问题,但即使在我的谷歌搜索之后,我仍然完全迷失了。

I've written a small Windows Service that does what my main application used to do in a background thread (it made sense to move it to a separate service for several reasons). 我写了一个小的Windows服务,做什么我用来在后台线程来执行主应用程序(这是有道理将其移动到一个单独的服务有以下几个原因)。

When the background thread was running as a part of my application it would fire an event every time it finished working (updating a database, in this case) and I would use a timestamp from that event to grab the appropriate information to update the window. 当后台线程作为我的应用程序的一部分运行时,它会在每次完成工作时触发事件(在这种情况下更新数据库),并且我将使用该事件的时间戳来获取更新窗口的相应信息。 I don't think the specifics are relevant, but please let me know if you need more details. 我不认为具体内容是相关的,但如果您需要更多详细信息,请告诉我。

Now that I've got the database-filling stuff running as a service, the question becomes: How do I replace what used to be done by the event? 既然我已经将数据库填充的东西作为服务运行,那么问题就变成了: 我如何替换事件过去所做的事情?

In other words, what's the simplest and/or most effective way to communicate a basic DateTime from my service to my app? 换句话说,将基本DateTime从我的服务传递到我的应用程序的最简单和/或最有效的方法是什么?

I've never done any IPC before but started reading up on it and got thoroughly confused. 我之前从未做过任何IPC,但是开始阅读并完全混淆了。 Named Pipes seem to be my best bet so far, but I've been unable to find anything that helps me understand their functionality... All I've found are poorly-commented chunks of code or "tutorials" that go way deeper than I need, without clearly covering the basics. Named Pipes似乎是我最好的选择,到目前为止,但我一直无法找到任何可以帮助我了解它们的功能......所有我发现有不良的注释的代码块,或者去比深刻“教程”我需要,没有明确涵盖基础知识。

So, without being able to establish a good base, I'm a little stuck. 所以,如果没有能够建立一个良好的基础,我有点卡住了。 What's the best method to implement simple communication that does what my event used to do and where can I learn the basics of that method? 实现简单通信的最佳方法是什么,它可以完成我的事件以及我在哪里可以学习该方法的基础知识?

EDIT: 编辑:

As always, everyone here rocks, thanks for all the quick responses. 一如既往,每个人都在摇滚,感谢所有快速反应。 Gerrie's link turned out to be exactly what I needed (though I didn't know that's what I needed at the time). Gerrie的链接结果正是我所需要的(虽然我不知道那是我当时需要的)。

Don't get scared away by the named pipes concept, WCF will take care of the nasty bits for you. 不要被命名管道概念吓跑,WCF将为您处理讨厌的事情。 You'll only have to do the configuration, it's simply another communication channel, instead of using HTTP for example. 您只需要进行配置,它只是另一个通信通道,而不是使用HTTP。 So you'll need to look into WCF. 所以你需要调查WCF。

Check out this tutorial . 看看这个教程

In other words, what's the simplest and/or most effective way to communicate a basic DateTime from my service to my app? 换句话说,将基本DateTime从我的服务传递到我的应用程序的最简单和/或最有效的方法是什么?

You should use named pipe in this scenario, though the other options that you have involve MSMQ , webservices. 您应该在此方案中使用命名管道 ,但您使用的其他选项涉及MSMQ ,webservices。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何实现 Windows 桌面服务和 Windows 桌面应用程序之间的通信? - How can I achieve communication between a windows desktop service and a windows desktop application? Windows服务和桌面应用之间的通信 - Communication between windows service and desktop app Windows服务和Windows窗体应用程序之间的通信 - Communication between Windows service and Windows form application Windows服务与桌面应用程序之间的交互 - Interaction between Windows service and desktop application 桌面应用程序和Windows Mobile Compact Framework c#之间的通信 - Communication between Desktop Application and Windows Mobile Compact Framework c# 桌面应用程序和Web应用程序之间的通信 - Communication between a desktop application and a web application Windows服务和在不同计算机上运行的桌面应用程序之间如何通信 - How to communicate between a windows service and a desktop application running on different machines 用于网站和桌面应用程序之间实时通信的NodeJS - NodeJS for realtime communication between website and desktop application Windows Service和WCF Service之间的通信 - Communication between windows service and wcf service NetMQ-Wcf服务与Windows Service之间的通信? - NetMQ - Communication between Wcf service to Windows Service?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM