Hello,
I have C# add-in for VS2005. From this add-in I create tool
window:
private void InitToolWindow()
{
if (_MyAddInWnd == null)
{
EnvDTE80.Windows2 toolWins =
(Windows2)_applicationObject.Windows;
object objOut = null;
_MyAddInWnd = toolWins.CreateToolWindow2(
_addInInstance,
Assembly.GetExecutingAssembly().Location,
"MyAddInAddIn.MyAddInCtrl",
"Caption string",
"{GUID string goes here}",
ref objOut
);
_MyAddInCtrl = (MyAddInCtrl)objOut;
}
}
Both user control and add-in are in the same assembly, so
everything goes smoothly. Except that user control being
created twice!
When user invokes menu command for my add-in and tool window
becomes visible for the first time, then new user control is
created, so `_MyAddInCtrl' member of `Connect' class has
nothing to do with newly created control.
I tried to use `Window.Object' property instead of member
variable:
InitToolWindow();
MyAddInCtrl addInCtrl =
(MyAddInCtrl)_MyAddInWnd.Object;
addInCtrl.SomeProp = 42;
...
The result is the same. Once `_MyAddInWnd' becomes visible
for the fist time, new user control is created.
How can I ensure that only one instance of user control is
created?
Thanks in advance
Alex
Alex Blekhman - 27 Nov 2007 09:35 GMT
> I have C# add-in for VS2005. From this add-in I create
> tool window:
> [...]
> Both user control and add-in are in the same assembly, so
> everything goes smoothly. Except that user control being
> created twice!
I discovered that actually the whole add-in is created
twice, not just user control. So, second creation of user
control is logical and expected. The real question now is
how to control the lifetime of an add-in. I'll start new
thread with appropriate subject.
Alex