Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Disposal of AutoSuspendHelper Instance#4012

Unanswered
JosiahDanger asked this question inQ&A
Discussion options

Hello all,

Thank you for your continued effort in developing and maintaining this MVVM framework.

I have a query regarding the ReactiveUI data persistence functionality, which is described in the guidebook onthis page. The context of my query is my FOSS app DateToday, which you can find atthis GitHub repository. This app is built with Avalonia and ReactiveUI. Avalonia also provides a brief guide to this data persistence functionalityhere.

So, I have followed the instructions available in both guides to successfully implement data persistence in my app. One facet of this functionality is AutoSuspendHelper class. I have instantiated this class inside my Application (see: App.axaml.cs, line num. 91).

1

The compiler raises warning CA2000: 'Dispose objects before losing scope'. The guides I referenced earlier do not address how to handle the disposal of objects of this class.

2

I would like to resolve this warning. I have taken the following steps to attempt to do so:

  1. If I dispose of this object at the end of the 'if' statement block, the app fails to persist its state to disk. This makes sense to me, because my understanding is that this object needs to be present in memory at the time of data persistence in order to facilitate this feature.

  2. If I inject a reference to this object into the constructor of my primary application window, and add it to my disposables, a new bug occurs in which the the application will crash when the user attempts to close it.

    3

    Please note that the same bug occurs if I instead call 'desktop.Shutdown()', where 'desktop' is my 'IApplicationLifetime' implementation. It seems that the disposal of the AutoSuspendHelper object in this fashion prevents the closing of the primary application window.

  3. One possible solution that I am not keen on is to subscribe to the 'IApplicationLifetime' 'Exit' event, and dispose of the AutoSuspendHelper instance in an event handler.

    4

    This approach does 'work' in that it demonstrably disposes of the AutoSuspendHelper instance, but it has a number of drawbacks in my opinion, including:

    • The compiler simply raises a different warning:

    5

    • I am not convinced, personally, that this event is guaranteed to fire.

Please can you confirm whether it is actually necessary to dispose of this object, and if so, how and when?

Let me know if you would like me to provide additional information.

Kind regards,
Joe

You must be logged in to vote

Replies: 0 comments

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
1 participant
@JosiahDanger

[8]ページ先頭

©2009-2025 Movatter.jp