private void DisposeTasks(object Buffer)
 {
     //bufferResult = null;
     //mySearchTasks = null;
     //ipList = null;
     _tasksChecking = null;
     _oldLines      = null;
     GC.Collect();
 }
Beispiel #2
0
 public IPSearchTask(int TaskId, uint firstIPAddress, uint Count, Action <IPInfo> BufferResultAddLine, int TimeOut, CancellationToken CancellationToken, ITasksChecking CheckTasks)
     : base(TaskId, firstIPAddress, Count, BufferResultAddLine, TimeOut, CancellationToken, CheckTasks)
 {
 }
        private void Start()
        {
            #region Create&Run Tasks

            #region Create&Run TasksChecking
            _mySearchTasks = new List <ISearchTask <IPInfo, uint> >();//[taskCount];


            _tasksChecking = new TasksChecking <IPInfo, uint>(
                //!myTasks,
                _mySearchTasks,
                StartButtonEnable,
                StopButtonEnable,
                ResultFillFromBuffer,
                DisposeTasks,
                SetProgress,
                _ipListCount,
                _bufferedResult);
            Task.Factory.StartNew(_tasksChecking.Check, _mySearchTasksCancel.Token, TaskCreationOptions.LongRunning, TaskScheduler.Current);
            #endregion

            #region (DISABLED) Get maxTaskCount from NumberOfCores
            //try
            //{
            //    var cpu =
            //        new ManagementObjectSearcher("select * from Win32_Processor")
            //        .Get()
            //        .Cast<ManagementObject>()
            //        .First();

            //    maxTaskCount = int.Parse(cpu["NumberOfCores"].ToString()) * 2 * 100;

            //}
            //catch (Exception)
            //{
            //}
            #endregion

            #region Create&Run IPSearchTasks


            //Get Each IPSearchTask IPAddresses range
            uint range = (uint)Math.Truncate((double)_ipListCount / _tasksCount);

            if (range == 0)
            {
                range       = 1;
                _tasksCount = (int)_ipListCount;
            }

            //Create & Run IPSearchTasks
            _logger.Info(string.Format("Create {0} tasks", _tasksCount));
            _logger.Trace(string.Format("{0,5} | {1,10} | {2,10} |", "No", "StartIndex", "Length"));
            for (int i = 0; i < _tasksCount; i++)
            {
                if (_mySearchTasksCancel.Token.IsCancellationRequested)
                {
                    _logger.Trace("Start was cancelled");
                    return;
                }
                uint         count        = ((i == _tasksCount - 1) ? _ipListCount - range * (uint)i : range);
                IPSearchTask ipSearchTask = new IPSearchTask(
                    i, _firstIpAddress + (uint)i * range, count, BufferResultAddLine,
                    _timeOut, _mySearchTasksCancel.Token, _tasksChecking
                    );
                _mySearchTasks.Add(ipSearchTask);
                _logger.Trace(string.Format("{0,5} | {1,10} | {2,10} |",
                                            i, i * range, (i == _tasksCount - 1 ? _ipListCount - range * i : range)));
                ipSearchTask.MyTask = (Task.Factory.StartNew(ipSearchTask.Start, TaskCreationOptions.LongRunning));
            }
            #endregion

            #endregion
        }
Beispiel #4
0
 public SearchTask(int TaskId, uint firstIpAddress, uint Count, Action <T> BufferResultAddLine, int TimeOut, CancellationToken CancellationToken, ITasksChecking CheckTasks)
 {
     this.Buffer               = new BufferedResult <T>();
     this.SubTaskStates        = new ConcurrentDictionary <TSub, bool>();
     this.ProgressDict         = new ConcurrentDictionary <uint, uint>();
     this.MyTask               = null;
     this.TaskId               = TaskId;
     this.CheckTasks           = CheckTasks;
     this.FirstIPAddress       = firstIpAddress;
     this.Count                = Count;
     this.CurrentPosition      = FirstIPAddress;
     this._timeOut             = TimeOut;
     this._bufferResultAddLine = BufferResultAddLine;
     this.IsPaused             = false;
     this.IsRunning            = false;
     this.IsBlocked            = false;
     this.WhoBlocked           = -1;
     this.WasStopped           = false;
     this.cancellationToken    = CancellationToken;
     this.Progress             = 0;
 }