private Match WaitFor()

in JetBrains.Profiler.SelfApi/src/Impl/ConsoleProfiler.cs [94:123]


    private Match WaitFor(Regex regex, int milliseconds)
    {
      var stopwatch = new Stopwatch();
      stopwatch.Start();
      var lineNum = _firstOutputLineToProcess;
      while (true)
      {
        lock (_outputLines)
        {
          while (lineNum < _outputLines.Count)
          {
            var line = _outputLines[lineNum++];
            var match = regex.Match(line);
            if (match.Success)
            {
              _firstOutputLineToProcess = lineNum;
              return match;
            }
          }
        }

        if (_process.HasExited)
          return null;

        if (!IsInfiniteTimeout(milliseconds) && stopwatch.ElapsedMilliseconds > milliseconds)
          return null;

        Thread.Sleep(40);
      }
    }