系统托盘应用程序和内存占用
我创建了一个小型应用程序,基本上存在于系统托盘中,用户只需要在极少数情况下打开实际应用程序。 问题是,一旦用户第一次打开应用程序,内存就会充满大量数据(用于数据网格、树视图等的 WPF UI)。 但随后用户将再次最小化该应用程序,并且该应用程序大部分时间都会停留在那里。 唯一始终可访问的 UI 是托盘图标的上下文菜单。
所以事情是这样的: 每次最小化应用程序时如何处理整个 UI?我在 WPF 中尝试了一些方法,但我永远无法摆脱 UI 对象,因为 WPF 保留对它们的引用。
我想要的是:打开应用程序(已加载 UI)-->最小化到托盘 -->整个 UI 被处理掉,剩下的唯一内存就是业务逻辑使用的内存...下次从托盘中打开应用程序时:整个 UI 被重建。
预先非常感谢您!
I have created a small application that, basically, exists in the system tray and the user only needs to open the actual application in VERY few cases.
The problem is, that once the suer opened the application for the first time, the memory is filled up with an awful lot of data (WPF UI for datagrids, treeviews etc).
But then the user will minimise the application again and it will sit there for most of the time.
The only UI that is always accessible is the tray icon's contextmenu.
So here is the thing:
How can I dispose of the WHOLE UI every time the application is minimised? I have tried several things in WPF but I can never get rid of the UI objects as WPF keeps references to them.
What I would love is: Open application (UI loaded) --> Minimise to tray --> Whole UI disposed and the only memory left is that used by the business logic... Next time application is opened from the tray: Whole UI is rebuilt.
Thank you very much in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想您可能有一个隐藏的主窗口,当它从托盘中恢复时,它将打开包含整个 UI 的 Window2,当您最小化应用程序时,可以关闭 Window2(从而处置)。或者也许可以通过双击托盘图标或通过上下文菜单直接打开 Window2...
但这仍然可能无法给出所需的结果,因为垃圾收集器通常不会收集垃圾,除非内存有压力子系统(例如,您的可用内存不足)。
尽管我已经看到垃圾收集器(或者可能是 Windows 功能)在最小化时将应用程序的大部分分页到交换文件。但我还没有深入研究这个问题,所以我不能说到底是什么原因或何时导致了这个问题。
I suppose you could have a hidden main window and when it gets restored from the tray it will open Window2 that will contain the WHOLE UI, when you minimize the app, Window2 can be closed (thus disposed). Or maybe it's possible to open Window2 directly when doubleclicking the tray icon or via the context menu...
But this still might not give the desired result, because the Garbage Collector usually doesn't bother with collecting garbage unless there is pressure on the memory subsystem (eg you are running out of free memory).
Although I have seen the garbage collector (or maybe it's a Windows feature) paging out most of the app to the swap file when it's minimized. But I haven't looked deeply into this so I can't say what or when exactly causes this.