不会触发C#COM事件

时间:2017-08-03 14:36:15

标签: c# events com

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

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

所以我猜这些事件在那里,但我在事件处理方面犯了错误。

感谢您的帮助。

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);
            };

        }
    }

}

1 个答案:

答案 0 :(得分:0)

我想发布解决方案TaiPan服务。要正确处理事件,您需要在visual basic的引用属性中将“嵌入互操作类型”设置为false。这是截图:

screenshot properties

希望这有助于其他人。