I had a look at the background worker and I believe this is the route I shall be going down. JMcilhinney I think that is the best way, because what I can do is run my code and then have my button disabled and once the application is back to life then the button can be enabled.
So using a background worker I have got to the following but I cant see a RunWorkerCompleted handle??
Also as stated below I use a background worker but it still hangs?
Public Class Form1
Private WithEvents BGWorker As System.ComponentModel.BackgroundWorker = Nothing
Private Shared ResetEvent As New AutoResetEvent(False)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' then my next bit of coding
Public Sub Start()
'Start the BackGroundWorker
BGWorker = New System.ComponentModel.BackgroundWorker
BGWorker.WorkerSupportsCancellation = True
Private Sub BGWorker_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BGWorker.DoWork
' Create my process
' Do my command
' Close my process
Public Sub Cancel()
'Stop the thread
If BGWorker.IsBusy Then
BGWorker = Nothing
'Kill the process
If myProcess IsNot Nothing Then myProcess.Kill()