Instancing IE modules

Add-in Express™ Support Service
That's what is more important than anything else

Instancing IE modules
 
Omri Suissa


Guest


In whatever way a tab (or window in IE6) is opened, this creates a new instance of the add-on (ADXIEModule)...
from your IE developer guide page 150.

this is not true.

I'm using IE9 and when i open more then 4 tabs (using "open in a new tab", not writing an url) some of the modules get events from more then one tab (even on connect and on disconnect events).

to check it i created a new addon:

private void InitializeComponent()
        {
            // 
            // IEModule
            // 
            this.HandleShortcuts = true;
            this.LoadInMainProcess = false;
            this.ModuleName = "MyIEAddon1";
            this.OnConnect += new AddinExpress.IE.ADXIEConnect_EventHandler(this.IEModule_OnConnect);

        }

private static volatile bool isOnConnectCalled = false;

        private void IEModule_OnConnect(object sender, int threadId)
        {
            if (isOnConnectCalled == true)
            {
                //WTF?
                System.Diagnostics.Debugger.Break();
            }

            isOnConnectCalled = true;
        }


This bug create a lot of problems in my project, can you help me with that?

Thanks,
Omri
Posted 06 Nov, 2011 07:46:31 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Hi Omri,

Sorry, I can't believe. All tabs/add-ons work in different threads. Please use the code below to get the current thread Id.

private void IEModule_OnConnect(object sender, int threadId)
{
Debug.WriteLine("Thread Id: " + AppDomain.GetCurrentThreadId().ToString());
}
Posted 07 Nov, 2011 04:06:17 Top
Omri Suissa


Guest


Hi Sergey,
You are right, there is a different thread but not a different instance ("... this creates a new instance ..."). therefore all static members are shared...

i solved that problem by saving each static member in a hashtable per thread.
Posted 07 Nov, 2011 04:09:40 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Also, please don't use static variables. To access all instances of the add-on you can use the GetModuleByIndex, GetModuleByThread, GetModuleCount, GetModuleIndex and AddinExpress.IE.ADXIEModule.GetModulesByTypeName methods of the iemodule.
Posted 07 Nov, 2011 04:16:18 Top
Omri Suissa


Guest


Why?
Posted 07 Nov, 2011 04:17:38 Top
Sergey Grischenko


Add-in Express team


Posts: 7233
Joined: 2004-07-05
Posted 07 Nov, 2011 04:23:14 Top
Omri Suissa


Guest


Thanks
Posted 07 Nov, 2011 04:24:30 Top