Uzamčený Async Code and Progress Issue

  • 15. dubna 2012 20:36
     
     

    Edited to point to the error 

    Stepping through the code right after my Task execution using async

    I got this error :

    "Exception has been thrown by the target of an invocation" seems referring to some innerExceptions regarding "null" and use "new" for instances ...

    --

    That was a "Null Exception" hidden in debugging

    The problem is solved with the help of Stephen












    • Upravený MHM-Mz 17. dubna 2012 18:38 The question path changed
    •  

Všechny reakce

  • 17. dubna 2012 15:04
    Moderátor
     
     Odpovědět
    I suggest turning on first-chance exceptions in Visual Studio and let the debugger break in when the exception occurs http://msdn.microsoft.com/en-us/library/d14azbfh.aspx.  It sounds like you're trying to dereference a null variable somewhere.
  • 17. dubna 2012 16:18
     
      Obsahuje kód

    Thanks Stephen, answering

    Yes, I think I should debug inside the task,

    Is the structure I built correct ?

    The Error I got is :

    "Exception has been thrown by the target of an invocation."
    The Error point to this line :

    Application.Run(new Main());

    The dialog shows InneException  of "NullReferenceException"

    and the VS doesn't help me to find which pieces of the code has thrown this error,

    before adding the Progress Reporting functionality it was working as expected

    stepping through the code I encounter an error right after the Task

                Task<MyCollection> theCollectingProcess = Task.Factory.StartNew(() =>
                {
                    MyCollection wResult = new MyCollection();
                    wResult = DoCollect(docProcess, progress,cts);
                    return wResult;    
                });
    If I be sure my code structure and lambda which I'm not professional in it yet is correct so I'll focus on the function itself and how it will report the Progress.


    • Upravený MHM-Mz 17. dubna 2012 16:21
    •  
  • 17. dubna 2012 16:48
    Moderátor
     
     

    You said that "VS doesn't help me to find which pieces of the code has thrown this error"... is that true even after following my suggestion of enabling first-chance exceptions so that VS breaks in when the exception occurs initially?

  • 17. dubna 2012 17:16
     
     

    Unfortunately your provided link didn't work for me at that time,

    seemed it had an extra parenthesis on it, now I'm going to read the article and debug it the right way,

    thanks,

    will inform you the result