Click here to Skip to main content
14,363,159 members
Rate this:
Please Sign up or sign in to vote.
hi all
I'm testing the new Microsoft cognitive service example,
the code below :
GitHub - microsoft/Cognitive-Samples-VideoFrameAnalysis: A library with sample apps for continuous analysis of live video, using the Microsoft Cognitive Services Vision APIs.[^]


when I try it returns an exception at FrameGrabber class
specifically at line 518 :

output.Analysis = await task;
the analysis is null, however, it's declared at line 78 as :
public AnalysisResultType Analysis { get; set; } = default(AnalysisResultType);

any suggestion to run the sample?

What I have tried:

/// <summary> Executes the analysis operation asynchronously, then returns either the
      ///     result, or any exception that was thrown. </summary>
      /// <param name="frame"> The frame. </param>
      /// <returns> A Task<NewResultEventArgs> </returns>
      protected async Task<NewResultEventArgs> DoAnalyzeFrame(VideoFrame frame)
      {
          CancellationTokenSource source = new CancellationTokenSource();

          // Make a local reference to the function, just in case someone sets
          // AnalysisFunction = null before we can call it.
          var fcn = AnalysisFunction;
          if (fcn != null)
          {
              NewResultEventArgs output = new NewResultEventArgs(frame);
              var task = fcn(frame);
              LogMessage("DoAnalysis: started task {0}", task.Id);
              try
              {
                  if (task == await Task.WhenAny(task, Task.Delay(AnalysisTimeout, source.Token)))
                  {
                      output.Analysis = await task;
                      source.Cancel();
                  }
                  else
                  {
                      output.TimedOut = true;
                  }
              }
              catch (Exception ae)
              {
                  output.Exception = ae;
              }

              LogMessage("DoAnalysis: returned from task {0}", task.Id);

              return output;
          }
          else
          {
              return null;
          }
      }
Posted
Updated 6-May-19 20:54pm
Comments
George Swan 1-Sep-19 7:34am
   
I wouldn't bother to set up the cancellation infrastructure for a task that's merely marking time. I’d just let it fizzle.
George Swan 1-Sep-19 11:17am
   
When an async method is cancelled in debug mode with the option 'Just My Code' enabled, Visual Studio will break and throw an exception. Try running in release mode and see if that resolves the problem. If it does, uncheck the 'Enable Just My Code' checkbox under Tools, Options, Debugging, General.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Talk to the authors: if you go to your link page, you will find a line:

Support questions: Stack Overflow[^]

Follow the link, and ask them.
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100