FolderBrowserDialog导致应用程序退出后仍保留在内存中吗? [英] FolderBrowserDialog causes app to stay in memory after exit?

查看:81
本文介绍了FolderBrowserDialog导致应用程序退出后仍保留在内存中吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#Windows Forms应用程序中创建新的FolderBrowserDialog()会导致该应用程序正常退出后,该应用程序仍留在内存中吗?

FolderBrowserDialog.ShowDialog()调用中获取结果后,我调用了Dispose()方法.但是,正常退出应用程序后,我可以使用Windows任务管理器,并查看该exe仍在进程列表中.
该应用程序具有很多形式,除了FolderBrowserDialog()之外,没有一个导致此问题.
有谁知道解决方法吗?

好的,因此我按照建议创建了一个小测试应用程序,而且可以肯定的是,该测试应用程序也存在相同的问题.
在测试应用程序中,我使用了Visual Studio 2010,并创建了一个新的Windows Forms项目.
然后,我在主窗体中添加了一个按钮.以下代码显示了按钮事件.
当我运行此测试应用程序时,只要我从未单击button1,该应用程序就会正常关闭.
如果我确实单击button1,则退出该应用程序后似乎可以正常退出.但是,使用任务管理器显示该exe仍然在进程选项卡中.
另一件事是,此问题仅来自运行发行版.在IDE调试器中运行不会导致此问题.显然,即使发行版exe仍然可以保留资源或其他内容,Visual Studio仍然知道如何清理.

该应用程序在Win XP SP3和.NET 4上运行.

Has anyone else run into a problem where creating a new FolderBrowserDialog() in a C# Windows Forms app causes the app to stay in memory after the app exits normally?

After getting the result from FolderBrowserDialog.ShowDialog() call, I called the Dispose() method. However, after exiting the app normally, I can use Windows Task Manager and see that the exe is still in the process list.
This app has lots of forms, and none of them cause this problem except FolderBrowserDialog().
Does anyone know of a workaround for this?

OK, so I created a little test app as suggested, and sure enough, the test app has the same problem.
In the test app, I used Visual Studio 2010 and created a new Windows Forms project.
Then, I added a button to the main form. The following code shows the button event.
When I run this test app, the app goes away normally as long as I never click the button1.
If I do click button1, then the app appears to exit normally when I quit it. However, using Task Manager shows the exe is still in the processes tab.
One other thing is that this problem only comes from running the Release version. Running inside the IDE debugger doesn''t cause this problem. Apparently, Visual Studio knows how to clean up even though the release exe somehow still holds on to resources or something.

This app is running on Win XP SP3, and .NET 4.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FolderBrowserTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            DialogResult result = fbd.ShowDialog();
            fbd.Dispose();
        }
    }
}

推荐答案

我不确定这是否行得通,但是值得一试.当程序关闭时(无论调用了什么方法或执行此操作的任何方法),请将其添加为最后一行代码:

I am not sure if this will work but it is worth a shot. When the program is closed (whereever or whatever method called to do this), add this as the last line of code:

//on Exit Event Handler Method or the program exit methods you use:
{
    //..... blah blah blah
    Environment.Exit(0);
    //you may use a different ExitCode to 0 but 0 should work fine. it does for me
}



这可能不是最专业的方法,但是如果没有其他方法,为什么不呢?)



it might not be the most professional way of doing it but if it works with no other way, why not;)


这篇关于FolderBrowserDialog导致应用程序退出后仍保留在内存中吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆