The following code causes a NullReferenceException
tStartParameter = String.Format(tStartParameter, tTo, tSubject)
tProcess = Process.Start(New ProcessStartInfo(tStartParameter) _
With {.UseShellExecute = True})
tProcess.WaitForExit()
tStartParameter is:
https://mail.google.com/?view=cm&fs=1&tf=1&to=t@example.com&su=boogaloo!!
Using the debugger I see that Process.Start is returning null. So.. any thoughts on why this is happening? I’d really like to block program execution until the user is done with the launched process.
UPDATE:
Refactoring the code to this:
tStartParameter = String.Format(tStartParameter, tTo, tSubject)
tProcess = New Process
tProcess.StartInfo = New ProcessStartInfo(tStartParameter) _
With {.UseShellExecute = True}
tProcess.Start()
tProcess.WaitForExit()
causes this exception:
InvalidOperationException: No process is associated with this object.
From MSDN, Process.Start will return:
In your case, since you’re passing a URL to Process.Start rather than an executable, you’re not actually kicking off a new process. You’re passing the URL to iexplore, or whatever your browser is. And so you get a null back.
In any case, what would it mean to “block program execution until the user is done with the launched process”? Wait until the user closes the web browser? In that case, you may want something like:
… which works appropriately for me. It does require you to specify the browser executable, though.