在WPF中使用Close()函数而不使用Close()

时间:2015-05-24 20:08:37

标签: c# wpf

所以这可能是一个无趣的问题,但这就是我想知道的。

假设我有两个屏幕,第一个屏幕是idk,例如 Screen1 。假设用户点击 Screen1 上的确定,将其带到 Screen2

我目前正在做的是关闭第一个屏幕( Screen1 ),以便屏幕不在后台,因为用户将不再需要该屏幕也不应该回到那个屏幕。

我的问题基本上就是这些:

  • 假设我没有在后台关闭前一个屏幕,这对该程序有何影响?
  • 是否会降低程序的速度,因为该屏幕仍在运行或者根本不会对程序产生影响?
  • 我只是在考虑效率问题。如果我不关闭(); 那个上一个屏幕,那真的很重要吗?

1 个答案:

答案 0 :(得分:3)

There is of course some amount of overhead in having a window open. It will receive various window messages from the operating system and process them. However, if the window is not really doing anything, then the overhead is insignificant. For example, you can open 20 copies of the Windows calculator and not see any noticeable degradation in your computer's performance because those windows are not really doing anything until you interact with them.

Basically, the difference between closing the window vs not is insignificant (unless the window is running animations or playing a video or something else causing it to change regularly).

So, you should probably be making the decision as to whether to leave the window open or not based on the desired user experience for your application. Since you stated that the user should never go back to that screen, then it probably makes sense to close it, but that is really up to the application designer (or whoever is thinking about the user experience for the application).