Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is Visual Studio skipping over my Exception from a ThreadPool work item?
    primarykey
    data
    text
    <p>I am aware of this other <a href="https://stackoverflow.com/questions/753841/how-to-catch-exceptions-from-a-threadpool-queueuserworkitem">post</a>, but it doesn't seem to apply to my situation.</p> <p>First off, here is my environment:<br> Windows XP 64-bit SP3; Visual Studio 2008 w/ SP; .NET 3.5 SP1; WPF application.</p> <p>My problem is that I cannot seem to step to where my exception happens. It just keeps running instead of continuing the debugging session.</p> <p>Here is some code -- I didn't write all of it, so please, no need for comments on naming :)</p> <pre><code>// start up the WPF application // set the handler for the Checked event ToggleButton channelButton1 = new ToggleButton(); channelButton1.Checked += (s, e) =&gt; ThreadPool.QueueUserWorkItem(SetTcpChannel, 1); </code></pre> <p>Then in that <code>SetTcpChannel</code> method:</p> <pre><code> try { int channel = (int)state; EnsureTcpSocket(); // more logic to do stuff with channel // that we don't care about for SO ... } catch (Exception e) { // just for illustration // this is where I expected the code to return ... } </code></pre> <p>And finally, in the place where the exception actually happens (inside <code>EnsureTcpSocket</code>):</p> <pre><code> if (_tcp == null) { // this is not a valid ip/port since the // target machine is not running (test condition) // but that's ok, I should get some exception // and continue debugging...right? _tcp = new TcpClient(ip, port); } </code></pre> <p>Here is what I have been doing:</p> <ol> <li>I set a breakpoint at the <code>EnsureTcpSocket</code> line inside <code>SetTcpChannel</code>,</li> <li>F11 (step-into) <code>EnsureTcpSocket</code> so I can see the <code>_tcp</code> piece of code</li> <li>Try to F10 (step-over) the <code>TcpClient</code> constructor</li> </ol> <p>At that last step, the application comes back up from the debugger and keeps running and I never see any exception.</p> <p>Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload