Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
tools
vsnet.act
vsnet.debugging
vsnet.documentation
vsnet.enterprise.tools
vsnet.general
vsnet.ide
vsnet.jlca
vsnet.servicepacks
vsnet.setup
vsnet.vsip
vsnet.vss
vsnet.vstools.office
vstudio.development
vstudio.extensibility
vstudio.general
vstudio.helpauthoring
vstudio.setup
vstudio.sourcesafe
  
 
date: Sat, 24 Nov 2007 19:51:42 +0200,    group: microsoft.public.vstudio.extensibility        back       


EnvDTE80.Windows2.CreateToolWindow2 woes   
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
date: Sat, 24 Nov 2007 19:51:42 +0200   author:   Alex Blekhman

Re: EnvDTE80.Windows2.CreateToolWindow2 woes   
"Alex Blekhman" wrote:
> 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
date: Tue, 27 Nov 2007 11:35:22 +0200   author:   Alex Blekhman

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us