Skip to content

Conversation

@dotMorten
Copy link
Member

}
try
{
// TODO: Check app manifest for background task declaration and provide better instructions how to register the background task
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this requirement be documented in the Readme about silent failures if not configured correctly?

Copy link
Contributor

@prathameshnarkhede prathameshnarkhede Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I was curious if the success and failure behavior are consistent across the platforms?

Comment on lines 83 to 85
private void SaveState(string? json)
{
using var file = File.Open(GetStateFilename(), FileMode.Create, FileAccess.Write, FileShare.Write);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This SaveState implementation is still crash‑unsafe and concurrency‑unsafe.

  • This truncates the file immediately and then writes the new content. LoadStateInternal has a chance to observe a half-written file.
  • If the process/thread dies mid-write, we end up with an empty or partially-written file.
  • With two possible writers (foreground or background), using FileShare.Write makes corruption more likely. Both file-opens will succeed but writes will be interleaved.

You can fix some of these issues by writing to a temp file and then doing an atomic replacement (File.Move for initial write, File.Replace for overwrites). The writers are still racing each other, but at least the file on disk will always be intact.

If you want to eliminate writer races, you can do some cross-process synchronization -- either a named mutex or a .lock file with FileShare.None.

@dotMorten dotMorten requested a review from mstefarov January 29, 2026 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants