Question Close form when directory opens

wilko

Member
Joined
Jan 7, 2011
Messages
6
Programming Experience
1-3
Does anyone know how to close a form when a directory opens?

I'll explain: i have created a very small app that basically opens a folder. Sounds simple and is easy to use, but the folder/directory opened is all based on user input, and this code the user enters determines where the folder is and on which server and so on....

Basically, it can take a while for the app to find and open the folder. I don't want the form to close until the directory has opened as i am displaying a 'loading...' message on the form. I was hoping it would be as simple as ... If directory.open(foldername) then me.close() .... but nope!

Does anyone know how to do this please?

Thanks
 
If you call WaitForInputIdle on your Process object before calling Close, does that about do it? The results are a bit unpredictable but hopefully it will work in this case.
 
That's a new one on me. How do i implement that? Would i be right in thinking that this waits until the process has started and has idled (no activity)? I'm no expert at VB but i do love learning these new things.

Cheers
 
Okay it works. This is the code i used, but the label doesn't change to "Fetching data,.....".

If Directory.Exists(fullpath) Then
Label1.Text = "Fetching data, please be patient..."
proc = Process.Start(fullpath)
proc.WaitForInputIdle()
Me.Close()
Else
Me.Close()
MessageBox.Show("Project not found!")
End If
 
What is likely happening is that execution gets to the WaitForInputIdle call before the UI is actually repainted after setting the Text of the Label. Try calling Application.DoEvents or the Label's Refresh method after setting the Text to force it to repaint immediately.
 
Back
Top