RTD server in vb.net - How to manage ConnectData

82 views
Skip to first unread message

sergio colnaghi

unread,
Sep 8, 2020, 7:02:19 AM9/8/20
to Excel-DNA
Hi, I'm writing my first rtd server in vb.net starting from an example in c#. 
 The ConnectData in c# is:

protecetd override ConnectData(Topic topic, IList<string>, topicInfo, ref bool newValues)
{   topics.Add(topic);
     .........}

in vb.net the ConnectData is:
Public Functions ConnectData(topicID as integer, byref strings as Array, ByRef new as boolean)

in c# I receive a topic object that I add to a list to manage when I need to updateValue. 
in vb.net I receive an integer and I can't understand how to manage it.

Can anyone help me, pleaese?

Thanks

Sergio

Govert van Drimmelen

unread,
Sep 8, 2020, 10:01:24 AM9/8/20
to exce...@googlegroups.com

Hi Sergio,

 

You might be comparing code in C# that uses the Excel-DNA ExcelRtdServer base class, with code form elsewhere in VB.NET that perhaps implements the IRtdServer interface directly.

 

I would suggest you base your VB.NET RTD server on the ExcelRtdServer base class too.

 

One sample that shows a minimal C# RTD server can be found here: https://github.com/Excel-DNA/Samples/blob/master/RtdClocks/RtdClock-ExcelRtdServer/RtdClockServer.cs

 

I pushed the file with the RTD server through the converter here: https://codeconverter.icsharpcode.net/

 

And the result looked like this:

 

Imports System.Collections.Generic

Imports System.Runtime.InteropServices

Imports System.Threading

Imports ExcelDna.Integration.Rtd

 

Namespace RtdClock_ExcelRtdServer

    <ComVisible(True)>                   ' Required since the default template puts [assembly:ComVisible(false)] in the AssemblyInfo.cs

    <ProgId(RtdClockServer.ServerProgId)>     '  If ProgId is not specified, change the XlCall.RTD call in the wrapper to use namespace + type name (the default ProgId)

    Public Class RtdClockServer

        Inherits ExcelRtdServer

 

        Public Const ServerProgId As String = "RtdClockVB.ClockServer"

 

        ' Using a System.Threading.Time which invokes the callback on a ThreadPool thread

        ' (normally that would be dangeours for an RTD server, but ExcelRtdServer is thrad-safe)

        Private _timer As Timer

        Private _topics As List(Of Topic)

 

        Protected Overrides Function ServerStart() As Boolean

            _timer = New Timer(AddressOf timer_tick, Nothing, 0, 1000)

            _topics = New List(Of Topic)()

            Return True

        End Function

 

        Protected Overrides Sub ServerTerminate()

            _timer.Dispose()

        End Sub

 

        Protected Overrides Function ConnectData(ByVal topic As Topic, ByVal topicInfo As IList(Of String), ByRef newValues As Boolean) As Object

            _topics.Add(topic)

            Return Date.Now.ToString("HH:mm:ss") & " (ConnectData)"

        End Function

 

        Protected Overrides Sub DisconnectData(ByVal topic As Topic)

            _topics.Remove(topic)

        End Sub

 

        Private Sub timer_tick(ByVal _unused_state_ As Object)

            Dim now As String = Date.Now.ToString("HH:mm:ss")

 

            For Each topic In _topics

                topic.UpdateValue(now)

            Next

        End Sub

    End Class

End Namespace

 

 

Let us know if that helps you to get the RTD server working.

 

-Govert

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/c7eb269a-0b4f-4ec2-a1cc-5e190dba82b7n%40googlegroups.com.

secol...@gmail.com

unread,
Sep 8, 2020, 11:32:42 AM9/8/20
to exce...@googlegroups.com

You’re right, I compared ExcelRtdServer with IrtdServer interface.

Your code is very useful, many thanks but, when I try to debug I receive this error:

 

Managed Debugging Assistant 'LoaderLock'

  Message=Managed Debugging Assistant 'LoaderLock' : 'Attempted execution within the OS Loader block. Do not try to run managed code inside a DllMain or image initialization function. This can cause the application to hang. ' (I translate from Italian😊).

 

Do you know how to solve it?

 

Thanks

 

Sergio

Govert van Drimmelen

unread,
Sep 8, 2020, 11:36:12 AM9/8/20
to exce...@googlegroups.com

HI Sergio,

 

That is an expected warning that comes when debugging, if the Excel-DNA IntelliSense service is installed.

You can safely check the box that lets you ignore this warning.

secol...@gmail.com

unread,
Sep 8, 2020, 11:37:46 AM9/8/20
to exce...@googlegroups.com

Wonderful, many thanks.

Reply all
Reply to author
Forward
0 new messages