Thanks guys,
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?
Code:
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
Start()
' then my next bit of coding
End Sub
Public Sub Start()
'Start the BackGroundWorker
BGWorker = New System.ComponentModel.BackgroundWorker
BGWorker.WorkerSupportsCancellation = True
BGWorker.RunWorkerAsync()
ResetEvent.WaitOne()
End Sub
Private Sub BGWorker_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BGWorker.DoWork
' Create my process
' Do my command
ResetEvent.Set()
' Close my process
End Sub
Public Sub Cancel()
'Stop the thread
If BGWorker.IsBusy Then
BGWorker.CancelAsync()
BGWorker = Nothing
End If
'Kill the process
If myProcess IsNot Nothing Then myProcess.Kill()
End Sub
Bookmarks