I have problem that watch expression is immediately interrupted when it comes to property that may use other thread. I don't want to have message "The function evaluation requires all threads to run", but still, I would like to use debugger feature of not executing potentially "unsafe" and long lasting properties.
I saw that ThreadAbortException is thrown when entering expression in Immediate Window, so I tried to handle this exception and continue execution of Watch Window thread execution while evaluating. But it didn't work.
I have next situation:
public partial class DummyClassWithDebuglessProperties
{
public static int countPrompt = 0;
public static int countSuccess = 0;
public static int countThreadAbortException = 0;
#region Properties
public string StringPropertyDebugFail
{
get
{
countPrompt++;
Debugger.NotifyOfCrossThreadDependency();
countSuccess++;
return "complex";
}
}
public string StringProperty
{
get
{
return "simple";
}
}
public string AllProperties
{
get
{
string stringPropertyDebugFail = "";
try
{
stringPropertyDebugFail = StringPropertyDebugFail;
}
catch (ThreadAbortException)
{
countThreadAbortException++;
stringPropertyDebugFail = "failedReading";
Thread.ResetAbort();
}
//expecting for watchWindow: simple, failedReading
//expecting in regular execution: simple, complex
return String.Format("{0}, {1}", StringProperty, stringPropertyDebugFail);
}
}
#endregion Properties
}
Debugging in test method:
[TestMethod]
public void ReadProperties()
{
DummyClassWithDebuglessProperties dummyClassWithDebuglessProperties = new DummyClassWithDebuglessProperties();
//Create watch for next
//dummyClassWithDebuglessProperties.AllProperties;
//breakpoint at the end.
}
It seems that ThreadAbortException is handled, but Thread.ResetAbort() doesn't have success with recovering thread that should initialize expression in Watch Window and when leaving Catch block it is being rethrown like ResetAbort doesn't have effect.
On the first evaluations of watches when reaching breakpoint, I have next situation:
Image - Initial try to read "unsafe" property
We see that property was prompted for reading and that ThreadAbortException occured. After clicking marked icon, "unsafe" reading is executed.
Image - Regular reading after button click
I'm interested for initial evaluation, is it possible to have evaluation such as:
simple, failedReading
Maybe Thread.ResetAbort() is ignored for Watch Window thread. Any ideas?
Related topics that are references:
Visual Studio during Debugging: The function evaluation requires all threads to run
Evaluation requires a thread to run temporarily. Use the Watch window to perform the evaluation