1.

Solve : Form loading problems - VB 2008?

Answer»

Hey guys,

I have a question regarding my code.

I'm using VB 2008 and have created a project that uses the Windows built in 'cleanmgr' to clean out old files, and then another FUNCTION runs on to search for spyware.
Each process is set into separate forms - when one completes it opens the next form and closes itself - or at least it should!

"desired process is form 1 opens form 2 (cleanmgr), then form 2 runs - and when complete exits and runs form 3, then 4 and so on"

What happens is form 1 runs the cleanmgr for form2 - but form 1 never closes, and form 2 never displays until the cleanmgr is completed which then displays form 3, then form 4, then form 2, then 3 and so!!

Here's my code:

Private Sub Form2_Load(BYVAL sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim clnmgr As Process
clnmgr = Process.Start("cleanmgr", "/sagerun:10101")

clnmgr.WaitForExit(240000)
' if the process doesn't complete within
' 4 MINUTES, kill it
If Not clnmgr.HasExited Then
clnmgr.Kill()
End If

Form3.Show()
Me.Close()

Any ideas most welcome.

TIAConsidering that forms are classes in .Net programming, it seems reasonable to treat them as such.

In each form load event, TRY creating an instance of the next form to be shown along with destroying the instance of the previous form.

Good luck.



Discussion

No Comment Found