Forum Discussion

bwehking's avatar
bwehking
Occasional Contributor
6 years ago

Let TryFind() return (a lot) faster for processes

Hi,

 

I try to determine in a loop whether certain processes are running and in turn handle different messageboxes that might appear. I noticed, that using 

driver.TryFind<IProcess>(new ProcessPattern() { ProcessName = "notExistingProcess" }, 1, 0, out var process);

takes more than 3 seconds on my machine, whereas 

Process.GetProcessesByName("notExistingProcess");

returns in a few (<10) milliseconds. I hoped that the timeOut parameter lets TryFind() return immediately, but obviously it's not the case.

 

Finding an existing process is fast:

driver.TryFind<IProcess>(new ProcessPattern() { ProcessName = "Explorer" }, 1, 0, out var process);

This takes 4 milliseconds.

 

Is there something I can do about it? Or do I have to use .NET Process class to check for the existing process first and only if it exists, use TestLeft to find the IProcess?

 

Thanks in advance!

4 Replies

    • bwehking's avatar
      bwehking
      Occasional Contributor

      Hi,

       

      thank you for your reply, but no, it doesn't speed up things. I ended up with a workaround. I created an C# extension method, that inserts that .NET framework call before it calls TrayFind().

       public static class TestLeftExtensions
          {
              public static IProcess TryFindProcess(this IDriver driver, string processName)
              {
                  if (System.Diagnostics.Process.GetProcessesByName(processName).Length == 0)
                  {
                      return null;
                  }
      
                  return Instances.Driver.Find<IProcess>(new ProcessPattern() { ProcessName = processName });
              }
          }

      It can be used like this:

      var process = this.Driver.TryFindProcess("NonExistingProcess");

      I would not consider this behaviour a "bug", but for me it's a "major inconvenience".

       

      I think this fix could be easily integrated into TestLeft directly.

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Hi,

         

        While it is good to know that you have (quite a pretty, from my point of view) a workaround for the problem, the problem itself sounds strange for me and I would really recommend to contact Support via the link mentioned earlier and listen for what they will reply. (You may reference this thread if you like and update it with Support's response for the benefit of others.)

         

  • Bobik's avatar
    Bobik
    Frequent Contributor

    Try set search depth parameter to zero.