protected virtual void AddInstanceEntry(MenuEntryConstructedArgs args)
 {
     ToolStripItem menuItem = args.ContextMenuItem;
       if (args.Position != MenuEntryPosition.BodyEntry)
       {
     return;
       }
       var relatedInstance = args.Instance;
       if (relatedInstance == null)
       {
     throw new InvalidDataException("menuItem.Tag is not Instance or is null");
       }
       this.ContextMenu[relatedInstance] = menuItem;
 }
 protected virtual void OnMenuEntryConstructed(object sender, MenuEntryConstructedArgs args)
 {
     if (this.CurrentState == CollectorState.MenuBuilded)
       {
     this.IsUnderConstruction = true;
     this.ContextMenu = new Dictionary<Instance, ToolStripItem>();
     this.CurrentState = CollectorState.MenuBuilding;
       }
       this.AddInstanceEntry(args);
 }
 protected virtual void OnMenuEntryConstructed(object sender, MenuEntryConstructedArgs args)
 {
     this.ConstructingWaiter.Wait();
       Instance relatedInstance = args.Instance;
       if (relatedInstance == null)
       {
     return;
       }
       ToolStripItem menuItem = args.ContextMenuItem;
       if (this.MarkedInstances.ContainsKey(relatedInstance.Name))
       {
     MarkedInstance markedInstance = this.MarkedInstances[relatedInstance.Name];
     this.MakeMenuItemMarked(menuItem);
     markedInstance.LastKnownToolstrip = menuItem;
       }
 }
 protected virtual void SendItemConstructedEvent(ToolStripItem item, MenuEntryPosition position, Instance instance)
 {
     var args = new MenuEntryConstructedArgs(item, instance, position);
       EventHelper.RaiseEvent(this.MenuEntryConstructed, this, args);
 }
 protected virtual void OnMenuEntryConstructed(object sender, MenuEntryConstructedArgs args)
 {
     //Product manager is initialized after this method is usually called. Because of that tray icons might be broken.
       this.ProductManagerInitialized.Wait();
       var relatedInstance = args.Instance;
       if (relatedInstance == null)
       {
     return;
       }
       ToolStripItem menuItem = args.ContextMenuItem;
       var icon = this.GetIconForInstance(relatedInstance);
       if (icon == null)
       {
     return;
       }
       menuItem.Image = icon;
 }