Exemple #1
0
 /// <summary>
 ///
 /// </summary>
 public void Start()
 {
     if (mIsAll)
     {
         if (NotifyType == RealDataNotifyType.All || NotifyType == RealDataNotifyType.Tag)
         {
             var vcount = ServiceLocator.Locator.Resolve <ITagManager>().ListAllTags().Count();
             mChangedId2 = new Databuffer((int)(vcount * 1.2));
             mChangedId1 = new Databuffer((int)(vcount * 1.2));
         }
         else
         {
             mChangedId2 = new Databuffer();
             mChangedId1 = new Databuffer();
         }
         mChangedIds = mChangedId1;
     }
     else
     {
         mChangedId1 = new Databuffer((int)(mRegistorTagIds.Count * 1.2));
         mChangedId2 = new Databuffer((int)(mRegistorTagIds.Count * 1.2));
         mChangedIds = mChangedId1;
     }
     mProcessThread = new Thread(ThreadProcess);
     mProcessThread.IsBackground = true;
     mProcessThread.Start();
 }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        private void ThreadProcess()
        {
            int i = 0;

            while (!mIsClosed)
            {
                resetEvent.WaitOne();
                if (mIsClosed)
                {
                    break;
                }

                resetEvent.Reset();

                if (NotifyType == RealDataNotifyType.Tag || NotifyType == RealDataNotifyType.All)
                {
                    if (ValueChanged != null && mChangedIds.Length > 0)
                    {
                        var vids = mChangedIds;
                        lock (mLockObject)
                        {
                            if (mChangedIds == mChangedId1)
                            {
                                mChangedIds = mChangedId2;
                            }
                            else
                            {
                                mChangedIds = mChangedId1;
                            }
                        }
                        ValueChanged?.Invoke(vids.Buffer, vids.Length);
                        vids.Length = 0;
                    }
                }

                if (NotifyType == RealDataNotifyType.All || NotifyType == RealDataNotifyType.Block)
                {
                    if ((BlockChanged != null) && i % 10 == 0)
                    {
                        i = 0;
                        lock (mBlockChangeds)
                        {
                            foreach (var vv in mBlockChangeds)
                            {
                                if (vv.Value.IsDirty)
                                {
                                    vv.Value.IsDirty = false;
                                    BlockChanged?.Invoke(vv.Value);
                                }
                            }
                        }
                    }
                }
                i++;

                Thread.Sleep(10);
            }
        }