I would like to delete a connector in my add-in. I know that there are a few topic about this, but I'm facing a new problem. I know the exact index of the connector I’d like to delete in the Connectors collection. I don’t try to delete this link in a loop. I use all the possible updating functions.
My code is the following:
try
{
short connectorNum = 0;
string last error = “”;
requirementElementTarget.Connectors.Delete(connectorNum);
requirementElementTarget.Connectors.Refresh();
requirementElementTarget.Update();
requirementElementSource.Connectors.Refresh();
requirementElementSource.Update();
lastError = requirementElementTarget.Connectors.GetLastError();
}
catch
{
//No exception here
}
The type of the variable requirementElementTarget and requirementElementSource are EA.Element. This code works, so it deletes the appropriate link. It doesn’t throw any exception and the lastError string is empty.
The bad part:
I have a Windows Form, where I implemented a BackgroundWorker, and I would like to call the link deleting code from there. I call other functions from this BackgroundWorker, they work fine. I can also call the link deleting function, it returns without any problem or exception. Finally I call the Windows Form’s ShowDialog() function, and this throws a System.Runtime.InteropServices.SEHException. Well I’m not a .NET genius so I don’t really know what does this exception mean, but I could figure out that this exception was coming from an other thread.
The StackTrace is the following:
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at EADOORSLinkSync.EADOORSLinkSyncAddinClass.callSnycScript(String updateMode) in C:\murajade\EA_scripts\EADOORSLinkSyncAddIn\trunk\EADOORSLinkSync\EADOORSLinkSync_Solution\EADOORSLinkSync\EADOORSLinkSyncAddinClass.cs:line 189
I can catch this exception, but it will kill EA anyway. After restarting EA, the connector doesn’t exist anymore. If I remove the “requirementElementTarget.Connectors.Delete(connectorNum);” line everything works without any problem.
I hope my problem is more or less clear.

Thank you in advance!