How to have a debug window that shows geometry and is fully responsible?

3 days ago 5
ARTICLE AD BOX

I have a project that manipulates geometry, and although I can step through the code and see the values, it's quite hard to verify everything without looking at the geometries that are being used/generated.

Can I use Visual Studio to have a "Geometry Debug" window that is fully responsive and accepts adding geomerty during debug of the main program?

I'm trying to make a WPF window that I can open during debug (via Immediate Window, for instance) and remains fully responsible to clicks and scrolls, while also accepting calls to add geometry to this window.

So far, I have been told that if I create and show the window in a new thread, I can have it fully responsible, but that is not the case. The window appears unresponsive, and only after a few lines are step over in the main program (the one being debugged)

This is the code for a (not exactly) viewmodel that the window binds to:

internal class WpfDebugGeometryVM { ... some properties to bind ... //a geometry collection bound to the window private ObservableCollection<DebugGeometry> _ChartObjects; public ReadOnlyObservableCollection<DebugGeometry> ChartObjects { get; private set; } //the window dispatcher for asynchronous calls private Dispatcher WindowDispatcher; //main method to show the window in another thread, called from immediate //returns the viewmodel to be able to add geometry from the Immediate public static WpfDebugGeometryVM? ShowDebugWindow() { WpfDebugGeometryVM? viewModel = null; ManualResetEvent threadStarted = new ManualResetEvent(false); Thread thread = new Thread(() => { SynchronizationContext.SetSynchronizationContext(new DispatcherSynchronizationContext(Dispatcher.CurrentDispatcher)); WpfDebugGeometry window = new WpfDebugGeometry(); WpfDebugGeometryVM localViewModel = new WpfDebugGeometryVM(window); window.SetDataContext(localViewModel); viewModel = localViewModel; threadStarted.Set(); window.Show(); Dispatcher.Run(); }); thread.SetApartmentState(ApartmentState.STA); thread.IsBackground = true; thread.Start(); threadStarted.WaitOne(); //the idea is to use this to add geometry from the Immedite Window return viewModel; } //viewmodel constructor, called only in the other thread private WpfDebugGeometryVM(WpfDebugGeometry window) { WindowDispatcher = window.Dispatcher; _ChartObjects = new ObservableCollection<DebugGeometry>(); ChartObjects = new ReadOnlyObservableCollection<DebugGeometry>(_ChartObjects); ChartExtents = new BoundingBox2d(0, 0, 1, 1); SetGeometryExtents(); } #region adding geometry //adds geometry using the Dispatcher public void AddPoint(Point2dGeom point, double radius, Brush color, bool updateZoom) { WindowDispatcher.BeginInvoke(() => { AddPoint(point, radius, color); if (updateZoom) ResetZoom(); }); } .... }

Is what I'm trying to do possible? Can I have this fully responsible window and add geometry from the Immediate window? (Right now, I need to step further in debug for the window to appear, and it's not really responsive)

Also, a breakpoing inside the Thread method is never hit (even though the window is actually shown at some point)

Read Entire Article