none
Excel 2016 RTD interface RRS feed

  • Question

  • Calls to ServerStart / ServerTerminate  in the IRTDServer interface seem to behave differently in Excel 2016 when compared to other versions.

    Please try this:

    ---------------------

    // Demo Excel 2016 RTD problem
    // this is basically https://github.com/JohnGreenan/ExcelRTDSimple.git
    // slightly modified to place breakpoints better

    // in Excel use =RTD("t16", 0)
    // in visual studio Debugging use Excel path:  C:\Program Files\Microsoft Office\Office16\EXCEL.EXE (for Excel 2016)
    // or C:\Program Files\Microsoft Office\Office15\EXCEL.EXE (for Excel 2013)

    // ****** Excel 2013 ******************
    // ServerStart is called 
    // ConnectData is called
    // Wait 5 sec
    // timerUpdate calls UpdateNotify
    // RefreshData is called and so on...
    // timerUpdate is called every 10s and calls UpdateNotify
    // all is ok

    // ***** Excel 2016**********************
    // ServerStart is called 
    // ConnectData is called
    // Wait 5 sec
    // timerUpdate calls UpdateNotify
    // Server start is called again creating a new instance  WRONG !!
    // ConnectData is called again WRONG
    // ServerTerminate is called for the first instance
    //
    //*** ALSO ******************************
    // if a document is open yet a new instance of the server is created

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Threading;
    using System.Diagnostics;
    using System.IO;
    using System.Runtime.InteropServices;
    using System.Runtime.Serialization;
    using System.Runtime.Serialization.Json;
    using XL=Microsoft.Office.Interop.Excel;


    namespace alignmentsystems.n2excel
    {
        [ComVisibleAttribute(true)]
        [
            Guid("80028E57-7832-4C62-B553-78326098D8CD"),
            ProgId("t16"),
        ]
        public class n2RTD: XL.IRtdServer
        {
            private readonly Dictionary<int, IncrementUpwards> _topics = new Dictionary<int, IncrementUpwards>();
            private Timer _timer;

            XL.IRTDUpdateEvent  _CallbackObject;

            public int ServerStart(XL.IRTDUpdateEvent CallbackObject)
            {
                _CallbackObject = CallbackObject;
                _timer = new Timer(delegate { timerUpdate(); }, null, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10));
                return 1;
            }

            public void ServerTerminate()
            {
                _timer.Dispose();
            }

            public void timerUpdate()
            {
                _CallbackObject.UpdateNotify();
            }

            public dynamic ConnectData(int TopicID, ref Array Strings, ref bool GetNewValues)
            {
                var start = Convert.ToInt32(Strings.GetValue(0).ToString());
                GetNewValues = true;
                _topics[TopicID] = new IncrementUpwards { CurrentValue = start };
                return start;
            }

            public void DisconnectData(int TopicID)
            {
                _topics.Remove(TopicID);
            }

            public int Heartbeat()
            {
                return 1;
            }

            public Array RefreshData(ref int TopicCount)
            {
                var data = new object[2, _topics.Count];
                var index = 0;

                foreach(var entry in _topics)
                {
                    ++entry.Value.CurrentValue;
                    data[0, index] = entry.Key;
                    data[1, index] = entry.Value.CurrentValue;
                    ++index;
                }
                TopicCount = _topics.Count;
                return data;
            }

        }
    }



    • Edited by Asgard-777 Sunday, October 4, 2015 10:14 AM
    Saturday, October 3, 2015 5:31 PM

All replies

  • Hi Asgard,

    Since I am not able to test in Excel 2016, I am trying to reproduce this issue in Excel 2016 preview. However it is failed.

    The code works well for me, here is the logs which I call the RTD functions in the first workbook, then create a new workbook and call the function in new workbook:

    37:01: ServerStart...
    37:01: ConnectData...
    37:06: timerUpdate...
    37:06: RefreshData...
    The thread 0x47d4 has exited with code 0 (0x0).
    The thread 0x33d8 has exited with code 0 (0x0).
    The thread 0x3b40 has exited with code 0 (0x0).
    37:16: timerUpdate...
    37:16: RefreshData...
    37:26: timerUpdate...
    37:26: RefreshData...
    The thread 0x25e8 has exited with code 0 (0x0).
    37:36: timerUpdate...
    37:36: RefreshData...
    37:46: timerUpdate...
    37:46: RefreshData...

    Here is code that I tested for your reference:

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Threading;
    using System.Diagnostics;
    using System.IO;
    using System.Runtime.InteropServices;
    using System.Runtime.Serialization;
    using XL = Microsoft.Office.Interop.Excel;
    
    namespace alignmentsystems.n2excel
    {
    
        [ComVisible(true)]
        [ProgId("alignmentsystems.n2RTD")]
        public class n2RTD : XL.IRtdServer
        {
            private readonly Dictionary<int, IncrementUpwards> _topics = new Dictionary<int, IncrementUpwards>();
            private Timer _timer;
    
            XL.IRTDUpdateEvent _CallbackObject;
    
            public int ServerStart(XL.IRTDUpdateEvent CallbackObject)
            {
                Debug.Print(String.Format("{0:mm:ss}: ServerStart...", DateTime.Now));
                _CallbackObject = CallbackObject;
                _timer = new Timer(delegate { timerUpdate(); }, null, TimeSpan.FromSeconds(5), TimeSpan.FromSeconds(10));
                return 1;
            }
    
            public void ServerTerminate()
            {
                Debug.Print(String.Format("{0:mm:ss}: ServerTerminate...", DateTime.Now));
                _timer.Dispose();
            }
    
            public void timerUpdate()
            {
                Debug.Print(String.Format("{0:mm:ss}: timerUpdate...", DateTime.Now));
                _CallbackObject.UpdateNotify();
            }
    
            public dynamic ConnectData(int TopicID, ref Array Strings, ref bool GetNewValues)
            {
                Debug.Print(String.Format("{0:mm:ss}: ConnectData...", DateTime.Now));
                var start = Convert.ToInt32(Strings.GetValue(0).ToString());
                GetNewValues = true;
                _topics[TopicID] = new IncrementUpwards { CurrentValue = start };
                return start;
            }
    
            public void DisconnectData(int TopicID)
            {
                Debug.Print(String.Format("{0:mm:ss}: DisconnectData...", DateTime.Now));
                _topics.Remove(TopicID);
            }
    
            public int Heartbeat()
            {
                return 1;
            }
    
            public Array RefreshData(ref int TopicCount)
            {
                Debug.Print(String.Format("{0:mm:ss}: RefreshData...", DateTime.Now));
                var data = new object[2, _topics.Count];
                var index = 0;
    
                foreach (var entry in _topics)
                {
                    ++entry.Value.CurrentValue;
                    data[0, index] = entry.Key;
                    data[1, index] = entry.Value.CurrentValue;
                    ++index;
                }
                TopicCount = _topics.Count;
                return data;
            }
    
        }
    
        public class IncrementUpwards
        {
            public int CurrentValue { get; set; }
        }
    
    }
    

    I would test this issue in Excel 2016 when the environment is build up. And I would be back if I have got any update.

    Regards & Fei



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, October 5, 2015 9:45 AM
    Moderator
  • Hello Fei,

    I found that if the formula is typed by hand or pasted from the clipboard then the problem does not happen.

    Did you input it by hand?

    Using your code I just tested Excel 2016 preview, Excel 2016 release and Excel 2013

    while opening a workbook containing a single formula    =RTD("alignmentsystems.n2RTD",,0)

    Both for Excel 2016 release and EXCEL 2016 preview:


    16:05: ServerStart...
    16:05: ConnectData...
    16:05: ServerStart...
    16:05: ConnectData...
    16:05: DisconnectData...
    16:05: ServerTerminate...
    16:10: timerUpdate...
    16:10: RefreshData...
    16:20: timerUpdate...

    Excel 2013 :

    21:09: ServerStart...
    21:09: ConnectData...
    21:14: timerUpdate...
    21:14: RefreshData...
    21:24: timerUpdate...
    21:24: RefreshData...
    21:34: timerUpdate...
    21:34: RefreshData...

    Thank  you

    A

    Monday, October 5, 2015 3:08 PM
  • Hi Asgard,

    >>I found that if the formula is typed by hand or pasted from the clipboard then the problem does not happen.

    Did you input it by hand?<<

    Yes. And after I save the workbook and reopen it, I am also able to reproduce this issue.

    Since the issue is complex, I suggest you contacting Microsoft support to raise an incident so that our engineer could work closely with him to identify the root cause and resolve this issue as soon as possible.

    If the support engineer determines that the issue is the result of a bug the service request will be a no-charge case and you won't be charged.

    Please visit the below link to see the various paid support options that are available to better meet your needs. http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, October 6, 2015 7:50 AM
    Moderator
  • Hello Fei

    No time to start this all over again.

    Please forward and bring someone interested on RTD to continue the discussion.

     I will be glad to help and do more tests if needed.

    Thank you for your time.

    Regards

    A



    • Edited by Asgard-777 Thursday, October 8, 2015 6:55 AM
    Wednesday, October 7, 2015 3:33 PM
  • Does anybody have workaround on this problem? No idea what the relationship between the duplicated ServerStart
    Thursday, October 29, 2015 2:18 AM
  • Hello there,

    I'm experiencing exactly the same problem with RTD server starting twice on XL 2016... The problem was reproduced with 16.0.6001.1034 and 16.0.4229.1002  MS Office versions.

    Is there anyone from MS to help with this REAL ISSUE ????

    Thanks

    • Proposed as answer by mFLR Thursday, November 5, 2015 2:03 PM
    • Unproposed as answer by mFLR Thursday, November 5, 2015 2:04 PM
    Wednesday, November 4, 2015 2:47 PM
  • Hi,

    Thanks for reporting the issue. This is being investigated. I will update once we have more information.

    Meanwhile, a temporary workaround is to explicitly pass the server name in the RTD formula.

    That is, if your current formula is like :

    =RTD(RealTimeServerProgID,,Topic1)

    then change it to :-

    =RTD(RealTimeServerProgID,"server name",Topic1)

    HTH,

    Praveen.

    Wednesday, November 11, 2015 7:14 PM
  • Hi Praveen

    Your fix seems to work from VBA / .Net however I tried a test on my XLL and the fix did not seem to work there. Would you expect it to solve the issue in an XLL as well?

    Thanks

    Shaun

    Friday, November 13, 2015 12:53 PM
  • Hi Shaun,

    If you're using Excel-DNA for the .xll add-in, the issue might be that Excel-DNA does not pass through the server name for internally hosted RTD servers.

    Do I understand correctly that you are passing hte name of the local computer as the server name, and that you still have an in-process RTD server?

    Excel-DNA could add the server name (the local computer name) when running under Excel 2016.

    For Excel-DNA I would appreciate it a lot if you could engage with your findings on the relevant issue on GitHub: https://github.com/Excel-DNA/ExcelDna/issues/40

    Regards,

    Govert

    Excel-DNA - Free and easy .NET for Excel

    Friday, November 13, 2015 1:06 PM
  • No I am not using Excel-DNA. It is my own C++ XLL. My application currently passes an empty string for the server parameter and I am also having issues with it on Excel 2016. I therefore tried the suggestion to pass a value in server name but my problem was not solved. Before troubleshooting further I wanted to confirm if this fix (of setting the server parameter) is expected to work from an XLL as well.

    Thanks

     
    Friday, November 13, 2015 1:12 PM
  • Hi Shaun,

    Inside your XLL, are you making the RTD call via the COM object model with Application.RTD, or via the C API with xlfRtd?

    -Govert

    Excel-DNA - Free and easy .NET for Excel

    Friday, November 13, 2015 1:29 PM
  • The C API with xlfRtd
    Friday, November 13, 2015 1:35 PM
  • Hi Shaun,

    Sorry, could not confirm if the workaround should take care of C API situation.  

    We have some good news -- The fix for MSI based Office 2016 has been released with December updates :-

    https://support.microsoft.com/en-us/kb/3114374

    The C2R version of the fix will be released in the coming months (don't have an exact month/date, yet).

    Thanks,
    Praveen.

    Thursday, December 10, 2015 2:07 PM
  • Hi Praveen

    The fix works thank you

    Let me ask you a somehow related question. Can we safely assume, while coding that there is only an instance of the RTD server at all times ?
    Without that assumption you have to  keep track not only of the topic but also of the corresponding server.
    That adds an extra layer of complexity.


    Wednesday, December 23, 2015 8:30 AM
  • Yes, it is correct to assume that there will be one instance of the RTD server COM Object based on progID.

    Thanks,
    Praveen.

    Wednesday, December 30, 2015 8:09 PM

  • This problem is still happening with Excel 16.0.11001.20074
    Monday, November 19, 2018 10:02 PM