如何在代码中完全重置 ac# 应用程序?
我有一个具有登录/注销功能的应用程序。当用户注销时,我想完全重置所有类和变量(我使用静态类,因此这使问题变得更加困难)。
我决定最好保留重置并完全重新加载应用程序 - 用户不会知道其中的差异,并且会清除任何可能的面包屑。
因此,我想了解以下任一方面的一些想法(以最好/最简单的为准)
1)通过关闭进程本身并重新启动来重新加载应用程序 2) 保持应用程序运行并重置所有数据和变量(包括窗口) - 可能通过 AppDomain.Unload / Load 或某些组合
有什么建议吗?
I have an app with login/logout functionality. When the user logs out, I want to completely reset all classes and variables (I use static classes so this makes the problem even harder).
I have decided that its best to just leave the resetting and do a total reload of the app - the user wouldn't know the difference and it would clear any possible breadcrumbs.
So I would like some ideas on either of the following (whichever is best/easiest)
1) Reload the app by closing the process itself and restarting
2) Keep the app running and reset all data and variables (including windows) - possibly by AppDomain.Unload / Load or some combo
Any advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能不想听到这个,但您现在遇到了这些问题,因为最初的设计很可能不正常。在静态上下文中存储与用户会话相关的数据通常不是最好的方法。
You probably don't want to hear this, but you're running into these issues now because the original design was most likely out of whack. Storing data related to a user session in a static context is usually not the best way to go about things.
如果选项 1 是一个有效的选项,那么它是迄今为止最简单的,所以这就是我要做的。
使用 AppDomains 作为沙箱并非没有问题,正如您从这个问题中看到的那样: .NET - 实现“捕获所有异常处理程序”的最佳方法是什么
If option 1 is a valid option, then it is by far the easiest, so that is what I would do.
Using AppDomains as a sandbox is not without its problems as you can see from this question: .NET - What's the best way to implement a "catch all exceptions handler"