FolderBrowserDialog - Thread Problem?

Allen G
12-23-2004, 11:15 PM
I'm seriously about to pull my hair out. I've been trying for hours to get this thing to work.

What I'm doing
Doing a folder browse operation from a Context Menu on the same form.

Private Sub Playlist_FolderAdd(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem8.Click
Dim b As New FolderBrowserDialog
b.Description = "Select a folder containing media."
b.ShowNewFolderButton = False
b.RootFolder = Environment.SpecialFolder.Desktop

If b.ShowDialog = DialogResult.OK Then
Debug.WriteLine(b.SelectedPath)
End If
End Sub

Exception Thrown:

System.Runtime.InteropServices.SEHException: External component has thrown an exception.
at System.Windows.Forms.Shell32.SHBrowseForFolder(BROWSEINFO lpbi)
at System.Windows.Forms.FolderBrowserDialog.RunDialog(IntPtr hWndOwner)
at System.Windows.Forms.CommonDialog.ShowDialog()
at Shock.frmMain.Playlist_FolderAdd(Object sender, EventArgs e) in E:\Shock\Shock\Dialogs\frmMain.vb:line 1886
at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
at System.Windows.Forms.MenuItemData.Execute()
at System.Windows.Forms.Command.Invoke()
at System.Windows.Forms.Command.DispatchID(Int32 id)
at System.Windows.Forms.Control.WmCommand(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativ eMethods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Shock.SubMain.Main() in E:\Shock\Shock\SubMain.vb:line 27


What is very weird is, I put this same exact code in the form load for instance, it'll throw the exception. But if I try the code in another project, works perfectly fine. Could this be a threading issue, some how? Even though everything is called form the same form.

Allen G
12-25-2004, 11:55 AM
I fixed this problem by making it a Shared Function inside of a Class. I guess that's the way you do it, can anyone explain why?

lebb
12-26-2004, 01:38 PM
I think we need some more information. Specifically, which line is generating the error? b.ShowDialog?

Iceplug
12-26-2004, 07:12 PM
The error is likely thrown on the ShowDialog line. Since the error comes from an API that the Folderbrowser component throws, it looks like a bug, unless one of your arguments are incorrect.
Since everything looks okay, I would ask if it worked if you specified the parent control for the ShowDialog or the FolderBrowser.

Allen G
12-27-2004, 01:05 AM
The error is likely thrown on the ShowDialog line. Since the error comes from an API that the Folderbrowser component throws, it looks like a bug, unless one of your arguments are incorrect.
Since everything looks okay, I would ask if it worked if you specified the parent control for the ShowDialog or the FolderBrowser.

I first had it where I dropped the control from the ToolBox onto the form. Then using it on the same form. It still threw an error. I also tried to reproduce this on another project, it worked fine. Also, it did not highlight any line or nothing when it throws the error.

The try/catch that is producing the error text is

Try
Application.EnableVisualStyles()
Application.DoEvents()
Application.Run(New frmMain)

Catch ex As Exception
Debug.WriteLine(ex.ToString)
End Try

I also tried doing the following line:

If b.ShowDialog(Me) = DialogResult.OK Then

It produces the same behavior.

It loads the Folder dialog up, it'll throw the error if I change the directory or move my mouse off of the dialog itself.

I did however find a fix for this. I created a Shared function inside of a class and it seems to work like a champ. I'm sorry I cannot give you any more details than what I have provided. It's very werid.

I've also had some problems where if I close a dialog and there is a list on the form, it will throw an error everytime. "Cannot access disposed object "ListBox". I think maybe the project is messed up or something :whoops:

If you guys are really wanting to solve/look at the issue at hand, I can provide the full source code. Email me: intolerance at gmail dot com

Iceplug
12-27-2004, 10:44 AM
Can you post it here?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum