Share data between main app and periodic task

前端 未结 4 1072
一个人的身影
一个人的身影 2020-12-10 16:01

I post this specific question after the other one I wasn\'t able to solve.

Briefly: even if I create a static class (with static vars and/or properties), main app

4条回答
  •  没有蜡笔的小新
    2020-12-10 16:10

    MS recommends the following:

    Communication Between Foreground Application and Background Agent

    Passing information between the foreground application and background agents can be challenging because it is not possible to predict if the agent and the application will run simultaneously. The following are recommended patterns for this.

    1.For Periodic and Resource-intensive Agents: Use LINQ 2 SQL or a file in isolated storage that is guarded with a Mutex. For one-direction communication where the foreground application writes and the agent only reads, we recommend using an isolated storage file with a Mutex. We recommend that you do not use IsolatedStorageSettings to communicate between processes because it is possible for the data to become corrupt.

    2.For Audio Agents: Store custom data in the Tag property of the AudioTrack class. For notifications from the audio agent to the foreground application, read the Tag property in the PlayStateChanged event handler. To pass data from the foreground application to the audio agent, read the Tag property of the current track in the implementation of the OnPlayStateChanged(BackgroundAudioPlayer, AudioTrack, PlayState) method.

    See here: http://msdn.microsoft.com/en-us/library/hh202944(v=vs.92).aspx

提交回复
热议问题