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();
}
}
}