C# COM 事件未触发

C# COM events are not fired

我正在尝试从 TaiPan Realtime COM 服务器获取事件。我能够从那里提取其他数据。访问密钥工作正常。

但是当我尝试获取事件时,该函数并没有以某种方式被触发。希望这是一个小错误。为了更好的可读性,我做了一个小的测试代码,这对你来说更容易阅读。将这些 ID 添加到 Stream 后,Visual Basic 调试器正在运行,它显示 cpu activity for com_test.

所以我想事件是存在的,但我在处理事件时犯了一些错误。

感谢您的帮助。

using System;
using System.Collections.Generic;
using TaiPanRTLib;

namespace com_test
{

    class Program
    {

        static void Main(string[] args)
        {

            var handle = new handle();

            handle.start();

            Console.ReadLine();

        }

    }

    public class handle
    {

        public int counter;

        //  this is a list contains the internal numbers of the taipan Software
        public static List<int> numbercodes = new List<int>(new int[] { 78379670, 78379685, 78379692, 78379669, 78379729, 78379672, 78379674, 78379698, 78379682, 78379681, 78379704, 78379689, 78379694, 78379673, 78379697, 78379687, 78379702, 78379690, 78379668, 78379671, 78379715, 78379666, 78379706, 78379727, 78379679, 127289939, 78379677, 78379693, 78379676, 78379678, 78379680, 78379688, 78379726, 78379686, 78379696, 78379675, 78379667, 78379703, 78379691, 78379684, 78379700, 78379699, 78379705, 78379695, 78379701, 78379664, 78379716, 78379982, 78379665, 78379707, 78379728, 78379717, 78379719, 7837971 });

        void TPRTDataStream_Bezahlt(int SymbolNr, float Kurs, float Volume, DateTime Zeit)
        {
            Console.WriteLine("peng"); // never see this in window - so not fired?
            counter += 1;
        }

        public void start()
        {

            TaiPanRealtime TPRTObject = new TaiPanRealtime();                   //  connects to launches Application
            DataStream TPRTDataStream = (DataStream)TPRTObject.DataStream;      //  attach to the DataStream Object.

            foreach (int db_num in numbercodes)
            {
                TPRTDataStream.Add(db_num, 0);                                  //  This adds the internal dbnumber to the Stream
            }

            TPRTDataStream.Bezahlt+=new _IDataStreamEvents_BezahltEventHandler(TPRTDataStream_Bezahlt);

            while (true)
            {
                Console.WriteLine(counter);     //  counter stays 0 all the time
                System.Threading.Thread.Sleep(1000);
            };

        }
    }

}

我想post找到TaiPan服务的解决方案。要正确处理事件,您需要在 Visual Basic 的引用属性中将 "Embed Interop Types" 设置为 false。这是截图:

screenshot properties

希望这对其他人有帮助。