ADXTopicCollection

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

ADXTopicCollection
 
Sergei Bubenko


Guest


Hello ADX Support,

I create ADXRTDTopic classes dynamically. In my code, when topic is disconnected, then I don't need it anymore.
I am concerning about disposing unused topics. How to do this in a right way?
Now I see that ADXTopicCollection.Topics variable is increasing dramatically, and I have 2-3 entries in ADXTopicCollection.TopicsID. Explicit call to ADXRTDTopic.Dispose has unpredictable results (NullReferenceException, ArgumentOutOfRangeException).

Please advise.

Thank you
Sergei
Posted 14 Jul, 2014 10:23:12 Top
Andrei Smolin


Add-in Express team


Posts: 18825
Joined: 2006-05-11
Hello Sergei,

Could you please explain how you create a topic dynamically? If you let Add-in Express create topic objects for you (by specifying "*" in a StringXX property) then Add-in Express is responsible for releasing such topic objects.


Andrei Smolin
Add-in Express Team Leader
Posted 15 Jul, 2014 05:23:30 Top
Sergei Bubenko


Guest


Hello Andrei,

I expose public function in RTDServerModule:


        public void CreateTopic(string key)
        {
            ADXRTDTopic rtdTopic = new ADXRTDTopic(components);
            rtdTopic.DefaultValue = "Loading...";
            rtdTopic.UseStoredValue = false;
            rtdTopic.String01 = "update";
            rtdTopic.String02 = key;
            rtdTopic.Connect += OnRtdTopicOnConnect;
        }

        private void OnRtdTopicOnConnect(object sender, EventArgs args)
        {
            ADXRTDTopic t = ((ADXRTDTopic) sender);
            TopicId = t.TopicID;
            Connected = true;
            PendingUpdate = true; // Initial value.

            t.RefreshData += OnRtdTopicOnRefreshData;
            t.Disconnect += OnRtdTopicOnDisconnect;
        }


Then I use this topic once in UDF:


object returnValue =
                    Module.CallWorksheetFunction(ADXExcelWorksheetFunction.Rtd,
                        new object[] { "comaddin_xll_rtd_cs.RTDServerModule1", "", "update", key });


Would you please demonstrate how to take advantage of "*"? I need to handle Connect/Disconnect/RefreshData for each topic.

Thank you,
Sergei
Posted 15 Jul, 2014 05:32:37 Top
Andrei Smolin


Add-in Express team


Posts: 18825
Joined: 2006-05-11
Sergei,

Thank you. I suppose with this approach the topic remains listed in one of Add-in Express collections.

Sergei Bubenko writes:
Would you please demonstrate how to take advantage of "*"?


Please see section "3. Excel RTD Server topics" at http://www.add-in-express.com/add-in-net/excel-rtd-servers.php.

You define a topic having one or more of the StringXX properties set to "*". At run time, you cast the sender parameter to ADXRTDTopic and retrieve the actual value passed to the topic.

Is this what you are looking for?


Andrei Smolin
Add-in Express Team Leader
Posted 15 Jul, 2014 06:18:33 Top
Sergei Bubenko


Guest


Andrei,

Thank you. It is clear now.

Regards
Sergei
Posted 15 Jul, 2014 07:44:37 Top
Sergei Bubenko


Guest


Andrei,

I've tried "*" in topic, but still I can see that internal ADXTopicCollection.Topics is not clearing.

My UDF function:


            public static object UdfSample(string key)
            {
                RTDServerModule1 rtdModule = Module.commonData.RTD;
                if (rtdModule == null)
                {
                    // Need to initialize RTD.
                    object notUsed = Module.CallWorksheetFunction(ADXExcelWorksheetFunction.Rtd,
                        new object[] { "comaddin_xll_rtd_cs.RTDServerModule1", "", "update" });

                    rtdModule = Module.commonData.RTD;

                    if (rtdModule == null)
                        throw new Exception("Failed load RTD module.");
                }

                object returnValue =
                    Module.CallWorksheetFunction(ADXExcelWorksheetFunction.Rtd,
                        new object[] { "comaddin_xll_rtd_cs.RTDServerModule1", "", "update", key });

                return returnValue;
            }


I made these calls in sequence (from the same Excel cell):

=UdfSample("topic1")
=UdfSample("topic2")
=UdfSample("topic3")
=UdfSample("topic4")
=UdfSample("topic5")

I also noticed that Connect and Disconnect events work as expected. But I see 6 entries in ADXTopicCollection.Topics (one for each requested topic) and 2 entries in ADXTopicCollection.TopicsID (with ids 4 and 5).

Regards
Sergei
Posted 15 Jul, 2014 09:08:17 Top
Andrei Smolin


Add-in Express team


Posts: 18825
Joined: 2006-05-11
Sergei,

ADXTopicCollection.Topics contains all ADXRTDTopic objects created in order to re-use an ADXRTDTopic should the same topic is used anew. As to ADXTopicCollection.TopicsID, it should contain the IDs of the currently used topics. Before a topic ID is removed from this collection, the Disconnect event for the corresponding ADXRTDTopic occurs.

Do you have any problem with the above?


Andrei Smolin
Add-in Express Team Leader
Posted 16 Jul, 2014 07:27:27 Top
Sergei Bubenko


Guest


Hi Andrei,

I will never reuse topics. Key will contain generated GUID or so. That's why I concern.

Regards
Sergei
Posted 16 Jul, 2014 07:32:23 Top
Andrei Smolin


Add-in Express team


Posts: 18825
Joined: 2006-05-11
Sergei,

We cannot delete an ADXRTDTopic object from ADXTopicCollection.Topics because a developer can cache this object when handling e.g. the ADXRTDTopic.RefreshData event.

We've never run into a problem related to the approach above. We could invent a way to delete unused topics. Say, it can be a method doing this. Still, we don't think this is required.


Andrei Smolin
Add-in Express Team Leader
Posted 16 Jul, 2014 08:08:40 Top
Sergei Bubenko


Guest


Andrei,

But ADXRTDTopic exposes IDisposable, though it doesn't work in run-time. Can it be fixed in the future?

Also I believe that topic declared with * shouldn't be cached because as a developer I expect to invoke any number of topic variations. At the higher level this issue prevents to build something like https://exceldna.codeplex.com/wikipage?title=Asynchronous%20Functions.

Regards
Sergei
Posted 16 Jul, 2014 08:29:50 Top