Hello
I noticed some cases where calling Topic.UpdateValue() does not update the target excel cells.
It happens rarely: about twice a week for a trading spreadsheet used by ~30 users.
The spreadsheet contains approx 5,000 cells with the "Subscribe" RTD user defined function below, which is used to stream spot prices (among other data).
When the issue happens, none of the cells receives updates.
[ExcelFunction(Description = "Subscribe to a data point updates")]
public static object Subscribe(
[ExcelArgument(Description = "Subscription key (data point indentifier)")] string key,
[ExcelArgument(Description = "(optional) Value when data point is missing. Default is empty string")] string defaultValue = "")
{
string[] topics = new string[2];
topics[0] = key;
topics[1] = defaultValue;
return XlCall.RTD("SubscribeExcelRtdServer", null, topics);
}
The function accepts a "key" (string) as input, which identifies a unique data point.
The data point is updated by a separate thread connected to internal applications.
When updates are received on this thread, a key value store (C# dictionary, attribute of the class SubscribeExcelRtdServer implementing ExcelRtdServer) is updated with the latest value received.
The publication to excel cells is managed by the function PublishExcelUpdates below, which is triggered by a timer event every 5 seconds (configurable).
I implemented this logic to control the frequency of updates sent to excel, and have more visibility and logs as there are thousands of updates per day.
public SubscribeExcelRtdServer()
{
Log.Info("SubscribeExcelRtdServer created.");
// create timer
int timerPeriod = 5000; // period in milliseconds
this.timer = new Timer(delegate
{
try { this.PublishExcelUpdates(); }
catch (Exception e) { Log.Error("Error at timer event: ", e); }
},
null, 0, timerPeriod);
Log.Info("Timer started. Frequency=" + timerPeriod + "ms");
}
The PublishExcelUpdates function does a loop over the key-value store in c# memory, and triggers the associated topic.UpdateValue() if needed.
I logged the number of calls to made to topic.UpdateValue() at each timer event to have more visibility.
public void PublishExcelUpdates()
{
long publishedCount = 0;
foreach (KeyValuePair<string, Topic> subscription in this.subscriptions)
{
Topic topic = subscription.Value;
try
{
if (!latestValues.ContainsKey(subscription.Key))
{
// no value to publish for the given key
continue;
}
if (latestValues.ContainsKey(subscription.Key) && publishedValues.ContainsKey(subscription.Key))
{
//if latest value = published value, do not publish
if (latestValues[subscription.Key] == publishedValues[subscription.Key])
{
continue;
}
}
// publish
object o = latestValues[subscription.Key];
topic.UpdateValue(o);
publishedCount++;
// store published value
if (this.publishedValues.ContainsKey(subscription.Key))
this.publishedValues[subscription.Key] = o;
else
this.publishedValues.Add(subscription.Key, o);
}
catch (Exception e)
{
Log.Error("Error at PublishExcelUpdates for topic: " + topic.TopicId + ": ", e) ;
}
}
Log.Info(publishedCount.ToString() + " topic values published in excel.");
}
When the issue occurs, excel stops updating completely, even though topics continue to be published during several hours.
Example of logs, after excel stopped updating:
[...]
2018-08-29 11:31:09,597 INFO - 112 topic values published in excel.
2018-08-29 11:31:14,606 INFO - 381 topic values published in excel.
2018-08-29 11:31:19,606 INFO - 199 topic values published in excel.
2018-08-29 11:31:24,615 INFO - 276 topic values published in excel.
2018-08-29 11:31:29,623 INFO - 135 topic values published in excel.
2018-08-29 11:31:34,632 INFO - 182 topic values published in excel.
2018-08-29 11:31:39,640 INFO - 127 topic values published in excel.
2018-08-29 11:31:44,648 INFO - 220 topic values published in excel.
2018-08-29 11:31:49,657 INFO - 172 topic values published in excel.
2018-08-29 11:31:54,657 INFO - 173 topic values published in excel.
2018-08-29 11:31:59,666 INFO - 218 topic values published in excel.
2018-08-29 11:32:04,675 INFO - 188 topic values published in excel.
2018-08-29 11:32:09,683 INFO - 156 topic values published in excel.
2018-08-29 11:32:14,693 INFO - 144 topic values published in excel.
2018-08-29 11:32:19,700 INFO - 143 topic values published in excel.
2018-08-29 11:32:24,708 INFO - 173 topic values published in excel.
2018-08-29 11:32:29,709 INFO - 144 topic values published in excel.
2018-08-29 11:32:34,718 INFO - 138 topic values published in excel.
2018-08-29 11:32:39,726 INFO - 167 topic values published in excel.
2018-08-29 11:32:44,734 INFO - 153 topic values published in excel.
2018-08-29 11:32:49,742 INFO - 154 topic values published in excel.
2018-08-29 11:32:54,750 INFO - 121 topic values published in excel.
2018-08-29 11:32:59,758 INFO - 143 topic values published in excel.
2018-08-29 11:33:04,767 INFO - 117 topic values published in excel.
[...]
I inspected the excel process of a user experiencing the issue; calculation mode was set to automatic, events activated... nothing unsual, but no RTD updates.
Starting a fresh excel process resolves the problem and updates start flowing again in the new one (even when keeping the 'dead' process open).
For info, Excel version used is 14.0.7212.5000 (32-bit), and the 32b xll compiled references ExcelDna.Integration 0.33.5730.40390.
Any help would be truly appreciated.
Thanks in advance