小编abh*_*ash的帖子

C#Backgroundworker和Twincat,如何在工作线程中触发通知事件

我对混合事件和线程知之甚少.场景是在PC上运行C#程序,在PLC上运行Twincat.我们需要在C#程序中访问PLC变量(已经完成了没有后台工作线程并且工作正常.)现在我们需要将这些处理移动到一个线程(最好是后台工作者).这是不起作用的代码.(表单包含一个START按钮,它将启动BGworker,一个STOP按钮将取消BGWorker,以及一个UPDATE按钮,它将值从PLC更新到文本框.),但现在tcClient_OnNotification没有被召唤!请指出我错过的地方,任何帮助将非常感谢.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;


    using System.Threading;         // not added by default
    using System.IO;                // not added by default
    using TwinCAT.Ads;              // not added by default

    namespace BGworker
    {
        public partial class Form1 : Form
        {
            private BackgroundWorker bw = new BackgroundWorker();
            private TcAdsClient tcClient;   // C# program is the client.
            private AdsStream dataStream;   // Data transfered through System IOStream
            private BinaryReader binReader; // We are now reading …
Run Code Online (Sandbox Code Playgroud)

c# events backgroundworker twincat

4
推荐指数
2
解决办法
5167
查看次数

标签 统计

backgroundworker ×1

c# ×1

events ×1

twincat ×1