WP7 inter process communication - windows-phone-7

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
Is there any way to enable inter-process communication in Windows Phone 7

In Windows Phone 8 SDK, we can now use system-wide Mutex object.
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.
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.)

try this:
phoneApplicationPage.State

Related

New instance without spawning a new process

I have noticed that some applications like firefox/iexplorer/windows image viewer etc are not creating new processes for new instances of the application. To explain what i mean i would expect that when opening two instances of firefox for example there would exist two different processes. Some other applications i tested had a process per instance.
My first question is why would someone use the one process multiple instances model? It seems a lot more complex to me than having an instance per process. I suppose that one reason may be resources usage.
My second question is how would you implement something like this? Assigning some threads to the new instance for example?
Firstly, one process for multiple "instances" keeps all the processes memory in one place, removing the need to use IPC to send messages between different "instances".
To implement something like this you can use the CreateMutex API here:
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682411(v=vs.85).aspx
If the mutex already exists and another instance of your app is launched, you can just forward the app open call to the existing instance of the app.

Best practise: Window Phone, how to sync files with a server

I am going to write some apps on WP 7.5 in C#, which should store some user input in files, and later on these files should be synced with a server.
However, internet connection might not always be available.
So, the app should store the data inernally first, and later on it should synchronize with the server in the background.
Now, is a background sync possible at all? If yes, are there any prebuilt-functionalities to do this? Or else, what is the 'best practice' to do such sychronizing tasks ?
Our file server's protocol can be chosen according to this task. We could even use a SQL server.
You need to read about "Background file transfers for Windows Phone":
http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202955(v=vs.105).aspx
Especially read and understand the policies and constraints regarding data size, duration, etc.
Note that this topic is part of the broader topic 'Multitasking for Windows Phone' which includes the background file transfers, tasks, etc:
http://msdn.microsoft.com/en-us/library/windowsphone/develop/hh202866(v=vs.105).aspx

Sending large byte stream buffer to another process

What is the best way to send a byte stream from one Windows process to another assuming that both processes are running as a Windows service? The data consists of an image buffer. Each service is running on a separate server on the same subnet.
Should the second service that is receiving the buffer be a web service (as opposed to a Windows service), even though it will never be called on a website (just internally)?
Is RPC the best method of communicating data between two windows services? There will be a lot of data passed and performance is key.
Development language is C# 4.0
I would suggest using sockets. RPCs have slight overhead over sockets and not worth the effort unless sending structured data.
If performance is key then use a shared memory segment. Look up CreateFileMapping and MapViewOfFile on MSDN. You can start from the aptly named "Creating Named Shared Memory" available at http://msdn.microsoft.com/en-us/library/windows/desktop/aa366551(v=vs.85).aspx

Is it possible to capture the rendering audio session from another process?

I am taking my first dives in to the WASAPI system of windows and I do not know if what I want is even possible with the windows API.
I am attempting to write program that will record the sound from various programs and break each in to a separate recorded track/audio file. From the reseacrch I have done I know the unit I need to record is the various audio sessions being rendered to a endpoint, and the normal way of recording is by taking the render endpoint and performing a loopback. However from what I have read so far in the MSDN the only interaction with sessions I can do is through IAudioSessionControl and that does not provide me with a way to get a copy of the stream for the session.
Am I missing something that would allow me to do this with the WASAPI (or some other windows API) and get the individual sessions (or individual streams) before they are mixed together to form the endpoint or is this a imposable goal?
The mixing takes place inside the API (WASAPI) and you don't have access to buffers of other audio clients, esp. that they don't exist in the context of the current process in first place. Perhaps one's best (not so good, but there are no better alternatives) way would be to hook the API calls and intercept data on its way to WASAPI, if the task in question permits dirty tricks like this.

Different ways to ask Windows to write data to disk

Usually, when an application writes to one of it's files on disk, the file modified timestamp changes.
Sometimes, and in my case it is an application written in ProvideX (a Business Basic derivative i believe) doing the writing, the modified timestamp does not change after a write. A program like MyTrigger will not pick up on the write operation either, but Sysinternals ProcessMonitor does log the disk activity.
It seems obvious that there are different ways to ask windows to perform write operations, and the request could then be hooked or logged in various different ways as well.
I need to be able to hook the write operations coming from the ProvideX application. Any pointers on the different ways windows writes to disk, and the type of hooks available for them would be greatly appreciated.
Thanks
User-mode process can write to the file either using WriteFile API function or using MMF, memory-mapped file API (CreateFileMapping/MapViewOfFile/Write to memory block). Maybe your application goes MMF way. MMF writes to files very differently from WriteFile API, but they both lead to the same end point - IRP sent to file system driver. File system filter driver (such as the one used by Sysinternals stuff) can track write requests on that IRP level. It is technically possible to distinguish between write operations initiated by MMF and WriteFile as different IRPs are sent (cached and non-cached writing is involved). It seems that directory change monitoring function in windows tracks only one IRP type, and this causes MyTrigger to miss the change.

Resources