What I have:
Dim test As Process = Process.Start("powershell.exe", "-executionpolicy
remotesigned -file C:\temp\test.ps1")
test.WaitForExit()
Finally while wait for "test" to exit, my GUI freezes. How to make it smooth?
What I have:
Dim test As Process = Process.Start("powershell.exe", "-executionpolicy
remotesigned -file C:\temp\test.ps1")
test.WaitForExit()
Finally while wait for "test" to exit, my GUI freezes. How to make it smooth?
You could use a BackgroundWorker to run this code on a separate thread, currently you are running it on the UI thread which causes it to freeze.
This should get you started:
Private Sub startWorker()
Dim powershellWorker As New BackgroundWorker
AddHandler powershellWorker.DoWork, AddressOf doWork
powershellWorker.RunWorkerAsync()
End Sub
Private Sub doWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
Dim test As Process = Process.Start("powershell.exe", "-executionpolicy remotesigned -file C:\temp\test.ps1")
test.WaitForExit()
End Sub
The test.WaitForExit() is a blocking method and it will block your UI thread. Try running the code in a parallel task and await it
Dim task As Task = Task.Run(Sub()
Dim test As Process = Process.Start("powershell.exe", "-executionpolicy remotesigned -file C:\temp\test.ps1")
Process.WaitForExit()
Return test
End Sub)
Dim test2 As Process = Await task
// some code that will execute after the process completes
You might need to add the async key word to outer method declaration.
Please note that I am a C# person :-)