コード例 #1
0
        public async Task ReadValues(List <Item> items)
        {
            var threadGroup = items.First().ThreadGroup;

            while (true)
            {
                try
                {
                    foreach (Item item in items)
                    {
                        try
                        {
                            var collector = new ItemCollector(item);
                            await collector.ReadValue();

                            await Task.Delay(threadGroup.IntervalBetweenItems);
                        }
                        catch (Exception ex)
                        {
                            Logger.LogMonitoringServiceLibrary(ex);
                        }
                    }

                    await Task.Delay(threadGroup.IntervalBetweenCycle);
                }
                catch (Exception ex)
                {
                    Logger.LogMonitoringServiceLibrary(ex);
                }
            }
        }
コード例 #2
0
        private void DoStart()
        {
            IndustrialMonitoringEntities Entities = null;

            try
            {
                Entities = new IndustrialMonitoringEntities();
                Items    = Entities.Items.ToList();
            }
            catch (Exception ex)
            {
                Logger.LogMonitoringServiceLibrary(ex);
            }

            foreach (var item in Items)
            {
                try
                {
                    if (item.ThreadGroupId == null)
                    {
                        ItemCollector itemCollector = new ItemCollector(item);
                        Thread        thread        = new Thread(() =>
                        {
                            itemCollector.ReadValueInfinite();
                        });
                        thread.Start();

                        ItemCollectors.Add(itemCollector);
                        Thread.Sleep(1);
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogMonitoringServiceLibrary(ex);
                }
            }

            var groups = Items.GroupBy(x => x.ThreadGroup).Select(x => x.First());

            foreach (Item item in groups)
            {
                try
                {
                    if (item.ThreadGroupId != null & item.ThreadGroupId > 0)
                    {
                        var itemsInGroup = Entities.Items.Where(x => x.ThreadGroupId == item.ThreadGroupId).ToList();

                        Thread thread = new Thread(() =>
                        {
                            ReadValues(itemsInGroup);
                        });

                        thread.Start();
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogMonitoringServiceLibrary(ex);
                }
            }

            this._serverStatus = ServerStatus.Run;
        }