Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
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 19: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

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.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900