简体   繁体   English

将数据发送到Windows窗体应用程序

[英]Send data to Windows Forms Application

I'm working on a program that is autostarting with windows. 我正在使用Windows自动启动程序。 The program is a windows-forms application written in C# . 该程序是一个用C#编写的windows-forms应用程序。 When it gets started, it automatically hides itself and shows a tray icon. 启动时,它会自动隐藏并显示一个托盘图标。 So it's only visible in tray, not in taskbar, not as a window. 因此,它仅在任务栏中显示,而在任务栏而不是窗口中可见。

Now I want somehow to send an ID (a simple int number) to the running windows form and the form should automatically show a messagebox with the recieved number. 现在,我想以某种方式将ID(一个简单的int编号)发送到正在运行的Windows窗体,该窗体应自动显示一个带有收到编号的消息框。

Sending should be directly, not over a database or a textfile that is watched. 发送应该是直接的,而不是通过数据库或被监视的文本文件。

Is there a way to send data to a open windows form? 有没有一种方法可以将数据发送到打开的Windows表单?

Any help apreciated :) 任何帮助感激:)

you can use the standard Windows APIs SendMessage (synchronous) or PostMessage (asynchronous / send and forget). 您可以使用标准的Windows API SendMessage (同步)或PostMessage (异步/发送并忘记)。 To use these APIs you must know the handle of the Windows Form / application main form. 要使用这些API,您必须知道Windows窗体/应用程序主窗体的句柄。

there are also other ways but this might be by far the simplest and would work from same or other process and is very lightweight for an integer only like you need to pass. 还有其他方法,但这可能是迄今为止最简单的方法,并且可以在相同或其他过程中使用,并且对于整数来说非常轻巧,只需要通过即可。

How about named pipes? 命名管道怎么样?

They are persistent, and easily accessible. 它们是持久的,并且易于访问。 Here's a blog post detailing both the 2.0 and 3.5 implementations: http://www.switchonthecode.com/tutorials/dotnet-35-adds-named-pipes-support 以下是详细介绍2.0和3.5实现的博客文章: http : //www.switchonthecode.com/tutorials/dotnet-35-adds-named-pipes-support

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM