简体   繁体   English

在同一应用程序的多个实例之间传递数据

[英]Passing data between multiple instances of same application

I have a WPF client application which can have maximum of one instance at any point of time, if the user runs the second instance it should pass the input arguments to first instance of application and quit. 我有一个WPF客户端应用程序,该应用程序在任何时间点最多可以有一个实例,如果用户运行第二个实例,则应将输入参数传递给应用程序的第一个实例并退出。 ie i run the first instance with argument "hello", and again starting new instance of same appln with new argument "welcome", noe the second instance should pass the data "welcome" to first instance and exit. 即我用参数“ hello”运行第一个实例,然后用新参数“ welcome”再次启动同一appln的新实例,否,第二个实例应将数据“ welcome”传递给第一个实例并退出。

Other that WCF and .Net remoting, is there any easiest and clean way to do it? 除了WCF和.Net远程处理之外,还有什么最简单,最干净的方法吗?

Currently I'm able to make the first instance as active, using WindowsEventHandle, but could not able to pass the data. 目前,我可以使用WindowsEventHandle将第一个实例设置为活动状态,但无法传递数据。 This is in same machine within same login 这是在同一登录名的同一台计算机上

这是非常基础的,但是您可以简单地写入文件,并让其他应用程序实例根据当前时间戳(以毫秒为单位)监视文件中具有唯一ID的新命令的新命令。

Yes of course. 当然是。 We tried multiple approaches, but the one using mutex`es seems to work the best. 我们尝试了多种方法,但是使用互斥锁的方法似乎效果最好。

here a some samples : How can I check for a running process per user session? 这里有一些示例: 如何在每个用户会话中检查运行的进程?

a good article about mutex`es http://odetocode.com/blogs/scott/archive/2004/08/20/the-misunderstood-mutex.aspx 关于互斥锁的好文章http://odetocode.com/blogs/scott/archive/2004/08/20/the-misunderstood-mutex.aspx

a simple implementation https://stackoverflow.com/a/19326/444149 一个简单的实现https://stackoverflow.com/a/19326/444149

If You search deeper, I'm sure there's a good sample in SO which shows how mutex events can be used to trigger something in another app instance 如果您进行更深入的搜索,我相信SO中会有一个很好的示例,该示例显示了互斥事件如何可用于触发另一个应用程序实例中的某些内容

Have a look at Memory-Mapped Files Since .NET 4 they have been available and can even share memory with unmanaged applications. 查看内存映射文件从.NET 4开始,它们已经可用,甚至可以与非托管应用程序共享内存。

Non-persisted memory-mapped files Non-persisted files are memory-mapped files that are not associated with a file on a disk. 非持久性内存映射文件非持久性文件是与磁盘上的文件不关联的内存映射文件。 When the last process has finished working with the file, the data is lost and the file is reclaimed by garbage collection. 当最后一个进程处理完文件后,数据将丢失,并且垃圾回收将回收该文件。 These files are suitable for creating shared memory for inter-process communications (IPC). 这些文件适用于为进程间通信(IPC)创建共享内存。

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

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