I created this macro in SDK sample Shapeappmacrorecordingcsharp and built it:
public void Macro3()
{
this.Visible = false;//<=set break point here
this.Visible = true;
}
1 Launch the IDE (out of process) from ShapeApp
2 Set breakpoint at this.Visible = false;
3 'Start Debugging' the macro project
4 Open the application's MacroManager
5 Run Macro3 and hit breakpoint at this.Visible = false;
6 F10 or Run produces this error:
"InvalidOperationException: Cross-thread operation not valid: Control 'ShapeAppForm' accessed from a thread other than the thread it was created on."
To 'fix' this, I set a property on ShapeAppForm: CheckForIllegalCrossThreadCalls = false;
/// <summary>
/// Internal constructor for this form.
/// </summary>
/// <param name="application">The active ShapeApp application instance.</param>
internal ShapeAppForm(Application application)
{
CheckForIllegalCrossThreadCalls = false;
InitializeComponent();
this.application = application;
sizeDialog = new SizeDialog();
locationDialog = new LocationDialog();
}
Re-build shapeappmacrorecordingcsharp, run and repeat steps 1-6
And there's no error.
But cross thread calls to winform UI "often leads to unpredictable results"
This means that when ISVs want to support robust OOP debugging, they need to use thread safe calls on their UI, which is demonstrated with the MacroDialog, but not in the rest of the UI that can be called from an Add-in.
For this one case, adding the asynch/thread safe Invoke to the Application Form did not work :
public new bool Visible
{
get
{
return this.Visible;
}
set
{
SetVisibleTS(value);
}
}
public delegate void VisibleDelegate(bool isVisible);
public void SetVisibleTS(bool isVisible)
{
if (InvokeRequired)
{
VisibleDelegate d = new VisibleDelegate(SetVisibleTS);
Invoke(d, new object[] { true });//Nope, this just hangs
}
else this.Visible = true;
}
so I'll have to look further and find something that does work:
Posted
Mar 07 2008, 10:17 AM
by
Gary