0

I have a Sub checking if a process name is listed in a listbox and if it exists it does some things, so i am checking the list of open processes looking for ones that have a window title.

Dim ProcCheck() As Process
    Dim MyProcCheck As Process

    ProcCheck = Process.GetProcesses

    For ProcIndex = 0 To ProcCheck.Length - 1

        MyProcCheck = ProcCheck(ProcIndex)

        If MyProcCheck.MainWindowTitle = "" Then Continue For

If I stop the code and read MyProcCheck variable at any point there is some errors for every process contained in this variable. Below is a picture of some of the errors that are shown. enter image description here

there are some other errors higher up in the list.

ExitCode = 'MyProcCheck.ExitCode' threw an exception of type 'System.InvalidOperationException'
ExitTime = 'MyProcCheck.ExitTime' threw an exception of type 'System.InvalidOperationException'

These errors are not causing any breaking of the code, they only show inside the dropdown that is in the picture. I tried googling the errors but all i can find is posts pertaining to starting processes. I am only reading the processes that are open already. Should I be worried about this ? thanks for any help you can give

Edit:

The Answer this question is linked with doesn't answer this question, it only explains a little more what the error being received is about. It is in no way a duplicate of the question I asked.

  • 1
    If you don't use those properties in your code (for the highlighted process) then you have nothing to worry. It is a side effect of the debugger trying to show something on the tooltip window for a process that doesn't allow this kind of access – Steve Aug 28 '22 at 08:48
  • 2
    The exception simply means that the operation you're trying to execute is not valid in this context or at this point of time. Attempting to access any of those properties will reveal the reason behind the InvalidOperationException. For example, if you write something like `Console.WriteLine(MyProcCheck.ExitCode)`, you get an exception with the following message: _"Process must exit before requested information can be determined."_ – 41686d6564 stands w. Palestine Aug 28 '22 at 08:51
  • Does this answer your question? [When to use InvalidOperationException or NotSupportedException?](https://stackoverflow.com/questions/12669805/when-to-use-invalidoperationexception-or-notsupportedexception) It's obviously a different question but the answer there explains what an InvalidOperationException is, which is what this question is essentially about. – 41686d6564 stands w. Palestine Aug 28 '22 at 08:53
  • Thanks for the quick replies and for the explanation, I now get why it's happening and yes I understand a bit more on the error and what it is. – Alex McCreath Aug 28 '22 at 09:04

0 Answers0