0

To start I would only rate myself as a novice programmer as I only know the concepts I've needed to learn to accomplish specific tasks at my work. That being said I'm using Process.Start to open the built-in Windows to camera program but when I do it leaves the process variable empty (nothing). Because of this I can't use Process.WaitForExit() as the code causes an error during execution.

Imports System.Diagnostics

Sub Main()
   Dim camTimeout as integer = 5 * 60000
   Dim camProcess as new System.Diagnostics.Process

   camProcess = System.Diagnostics.Process.Start("microsoft.windows.camera:")

   If Not camProcess.WaitforExit(camTimeout) then
      MsgBox("timeout")
   Else
      MsgBox("picture")
   End if
End Sub

During execution the camera app opens but I get a "NullReferenceException" at camProcess.WaitForExit. This is because camProcess is Nothing and I don't understand why that is. Can someone explain why camProcess isn't set properly when the camera app starts or point me to some novice-level reference material. Thanks!

Edit: This code is in a Windows Form Application.

LarsTech
  • 80,625
  • 14
  • 153
  • 225
Chris P.
  • 1
  • 1
  • 1
    good info here: https://stackoverflow.com/questions/43522654/process-start-launches-the-process-but-returns-null – Sam Axe May 29 '18 at 19:06
  • Thanks @SamAxe! That link was perfectly useful. I don't know if this is the best solution but it works [see edit]. – Chris P. May 29 '18 at 19:35
  • 1
    If you have an answer, post it as an answer, not in the question. – LarsTech May 29 '18 at 19:50
  • I'll be more than happy to make that change if you can undo your edit that erased what I had already written. Being my first question and all it would have been nice of you to advise me that what I did wasn't the preferred method and allow me to fix it without having to re-create it. – Chris P. May 30 '18 at 04:07

0 Answers0