Question Bug when setting FolderBrowserDialog1.SelectedPath in code

AbacusData

New member
Joined
Dec 3, 2008
Messages
4
Programming Experience
10+
Do you know why this happens?
VB.NET:
    If (strCampaignFolder <> "") Then
      'Next line works fine when strCampaignFolder already has a value set by FolderBrowserDialog1.SelectedPath further below.
      FolderBrowserDialog1.SelectedPath = strCampaignFolder
    Else  'PROBLEM: Next line causes the external .NET code 'UnsafeNativeMethods' to put the app to sleep when strCampaignFolder has no existing value!
      FolderBrowserDialog1.SelectedPath = "L:\InternetMarketing\AdWordsCampaigns\LiveChat-Software"
    End If
    If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
      'Get Campaign folder
      strCampaignFolder = FolderBrowserDialog1.SelectedPath
    End If
Can you suggest a workaround, please?
 
Last edited by a moderator:
VB.NET:
    If (strCampaignFolder <> "") Then
      'Next line works fine when strCampaignFolder already has a value set by FolderBrowserDialog1.SelectedPath further below.
      FolderBrowserDialog1.SelectedPath = strCampaignFolder
    Else  'PROBLEM: Next line causes the external .NET code 'UnsafeNativeMethods' to put the app to sleep when strCampaignFolder has no existing value!
      FolderBrowserDialog1.SelectedPath = "L:\InternetMarketing\AdWordsCampaigns\LiveChat-Software"
    End If
    If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
      'Get Campaign folder
      strCampaignFolder = FolderBrowserDialog1.SelectedPath
    End If

Placing code brackets makes the code much easier to read. It is
[CODE]your code here[/CODE]
 
Last edited by a moderator:
Exactly what do you mean by "put the app to sleep"? If you mean that the app hangs, is it indefinitely or just for a period? On what line? Is that path a local folder or on a network drive?
 
Thanks for responding.

The L: drive is on the local PC and presents no problem. That path works fine after the user selects the folder manually in the FolderBrowserDialog1; The same path is then stored in the variable strCampaignFolder. Thereafter the FolderBrowserDialog1 opens with that folder already selected, because the code sets FolderBrowserDialog1.SelectedPath = strCampaignFolder. This is what I want to happen when the app first starts, and the FolderBrowserDialog1 has not yet been used manually and .SelectedPath therefore has received no value. I want the FolderBrowserDialog1 to open with that local folder already selected, so that the user does not have the bother of navigating to it from the default Desktop folder after starting the app.

This should be a simple thing to do, but it is not happening. The external error occurs instead. The actual line stopping the execution is in 'private void WindowThreadProc()' in 'SystemEvents.cs':
[CODE}
int ret = UnsafeNativeMethods.MsgWaitForMultipleObjectsEx(0, IntPtr.Zero, 100, NativeMethods.QS_ALLINPUT, NativeMethods.MWMO_INPUTAVAILABLE);
if (ret == NativeMethods.WAIT_TIMEOUT) {
Thread.Sleep(1);
}
[/CODE]

It is strange that the same value (the path to the folder) can be assigned to .SelectedPath only after the FolderBrowserDialog1 has been used manually, but not when it is opened for the first time.
 
Back
Top