WP7进程间通讯 [英] WP7 inter process communication

查看:91
本文介绍了WP7进程间通讯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用WP7上的背景音频播放器代理构建音乐播放器。我想启用UI部分和代理部分之间的通信。许多指南建议使用隔离存储,但这不是一个好方法

I am building an music player using Background audio player agent on WP7. I want to enable communication between the UI part and the agent part. Many guides suggest using isolate storage, but I think that is not a good way

是否有任何方法可以启用进程间Windows Phone 7中的通讯

Is there any way to enable inter-process communication in Windows Phone 7

推荐答案

在Windows Phone 8 SDK中,我们现在可以使用系统范围的Mutex对象。

In Windows Phone 8 SDK, we can now use system-wide Mutex object.

似乎前台应用程序和后台代理在电话上作为单独的进程运行。因此,即使实例化相同的类,每个进程也具有不同的 instance

It seems the foreground App and Background Agent run as separate processes on the phone. So even when you instantiate the same class, each process has a different instance.

到目前为止,我所知道的最好的解决方案是让每个进程将共享数据结构映射到隔离存储文件,然后使用系统范围的Mutex(称为Mutex)。 ),以防止一个进程在另一个文件写入时读取文件。如果一个进程始终是数据结构的编写者,这将变得更加简单,因此它不必担心异步地合并另一个进程所做的更改。如果每个进程必须是数据结构某些部分的编写者(通常情况下),请考虑将这些部分分成单独的数据结构和单独的独立存储文件,其中一个进程读取一个文件,然后写入另一个文件,另一个进程写入第一个文件。并阅读第二篇。 (所有互斥量内的读写操作。对于文件和两个进程均使用 same 互斥量,以避免死锁。)

The best solution I know about so far is to have each process map the "shared" data structure to an Isolated Storage file, then use a system wide Mutex (named Mutex) to prevent one process from reading the file when the other is writing it. It'll be simpler if one process is always the writer of the data structure, so it never has to worry about merging in changes made by the other process asynchronously. If each process must be the writer of some portion of the data structure, the usual case, consider separating those portions into separate data structures and separate Isolated Storage files, with one process reading one file and writing the other and the other process writing the first and reading the second. (all reads and writes within mutex. Use same mutex for both files and both processes to avoid deadlocks.)

这篇关于WP7进程间通讯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆