Beispiel #1
0
        /// <summary>
        /// 运行程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            if (button1.Content.ToString() == "停止运行")
            {
                foreach (var item in states)
                {
                    //释放内存
                    ((Timer)item.UserToKen).Dispose();
                    if (!item.CurrentProcess.HasExited)
                    {
                        item.CurrentProcess.Kill();
                    }
                }
                try
                {
                    //移除组播
                    udp.DropMulticastGroup(System.Diagnostics.UDPGroup.group.ep.Address);
                    udp.Close();

                    states.Clear();
                    task.Dispose();
                }
                catch (Exception ex)
                {
                }
                button1.Content = "开始运行";
            }
            else
            {
                //当前已经采集的索引
                if (System.IO.File.Exists(ProgressFileName))
                {
                    List <string> arr = System.IO.File.ReadLines(ProgressFileName).ToList();
                    foreach (var item in Strs)
                    {
                        //得到当前项的状态如果包含则将当前项设置为 true 表示已经处理过了
                        if (arr.Contains(item.Key))
                        {
                            item.Value.IsCollectioned = true;
                        }
                    }
                }
                //初始化采集进程
                System.Linq.Enumerable.Range(0, MaxPorcess).ToList().ForEach((p) =>
                {
                    System.Threading.Thread.Sleep(40);
                    AddStates();
                });


                //开始监听
                task = System.Threading.Tasks.Task.Factory.StartNew(() =>
                {
                    udp = new System.Net.Sockets.UdpClient(System.Diagnostics.UDPGroup.group.ep.Port);
                    udp.JoinMulticastGroup(System.Diagnostics.UDPGroup.group.ep.Address);
                    udp.BeginReceive(AsyncCallback, udp);
                });
                button1.Content = "停止运行";
            }
        }
        /// <summary>
        /// Returns the result of a task. If the task does not return a result, this method will return null.
        /// </summary>
        /// <param name="task">The task to run.</param>
        /// <returns>Null if there is not result.</returns>
        internal dynamic RunTaskSynchronously(System.Threading.Tasks.Task task)
        {
            task.Wait();
            var type = task.GetType();

            if (!type.IsGenericType)
            {
                task.Dispose();
                return(null);
            }
            else
            {
                dynamic result = type.GetProperty(nameof(System.Threading.Tasks.Task <System.Object> .Result)).GetValue(task);
                task.Dispose();
                return(result);
            }
        }
Beispiel #3
0
 internal void StopInsideTask()
 {
     _tokenSource.Cancel();
     if (_insideTask == null)
     {
         return;
     }
     _insideTask.Wait(2000);
     _insideTask.Dispose();
     _insideTask = null;
 }
Beispiel #4
0
        static StackObject *Dispose_4(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Threading.Tasks.Task instance_of_this_method = (System.Threading.Tasks.Task) typeof(System.Threading.Tasks.Task).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack), (CLR.Utils.Extensions.TypeFlags) 0);
            __intp.Free(ptr_of_this_method);

            instance_of_this_method.Dispose();

            return(__ret);
        }
        /// <summary>
        /// Await the given task and returns its value of null if the task is a void.
        /// </summary>
        /// <param name="task">The task to run.</param>
        /// <returns>Null if the task is a void.</returns>
        internal async System.Threading.Tasks.Task <dynamic> RunTask(System.Threading.Tasks.Task task)
        {
            await task;

            if (!task.GetType().IsGenericType)
            {
                task.Dispose();
                return(null);
            }
            else
            {
                return(task);
            }
        }
        public void Dispose()
        {
            if (_isDisposed)
            {
                return;
            }

            _isDisposed = true;
            //DataReceived -= OnSerialPortDataReceived;
            //_tcpClient.ErrorReceived -= OnSerialPortErrorReceived;

            _networkStream?.Dispose();
            _tcpClient?.Dispose();

            _task?.Dispose();
            _task = null;

            GC.SuppressFinalize(this);
        }
        /// <summary>Cleans up the timer and the installer task after the task is finished.</summary>
        /// <returns>If the task has thrown an exception, this exeption is returned. Otherwise, the return value is <c>null</c>.</returns>
        private AggregateException InstallerTaskCleanup()
        {
            _timer.Tick -= EhInstallationTimerTick;
            _timer.Stop();
            _timer = null;

            var exception = _installerTask.Exception;

            _installerTask.Dispose();
            _installerTask           = null;
            _isCancellationRequested = false;

            _installerFinishedSuccessfully = (null == exception);
            _btOk.IsEnabled       = true;
            _btTryAgain.IsEnabled = !_installerFinishedSuccessfully;
            _btCancel.IsEnabled   = false;

            return(exception);
        }
Beispiel #8
0
 public void Stop()
 {
     _Stop = true;
     _Task.Wait();
     _Task.Dispose();
 }
Beispiel #9
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Count"></param>
        public void GenerateChildren()
        {
            //int Count = 0;
            #if GUIOUTPUT
            double Prog = 0d;
            ProgressDisplay Disp = new ProgressDisplay();
            System.Threading.Tasks.Task t = new System.Threading.Tasks.Task(new Action(Disp.Show));
            t.Start();
            #endif
            //Reduce the image into simplicity
            mLeftover = (Bitmap)mBaseImage.Clone();
            ImgManip Man = new ImgManip(ref mLeftover);
            Man.ReduceColors(mColorDetail);
            mScale = Man.ReduceGrid(mResDetail);
            mLeftover = Man.GetImage;
            Bitmap Clear = new Bitmap(mLeftover.Width, mLeftover.Height);
            Graphics.FromImage(Clear).Clear(Constants.ALPHA_FULL);
            ImageSection Img = new ImageSection(new Point(0, 0), mLeftover, Clear, Color.Empty);

            mChildren = Child.ScanImageSection(Img, mColorForgive, mColorDetail, mMinMargin);
            #if GUIOUTPUT
            Prog = 0.5d;
            #endif
            //Count += mChildren.Length;
            double Scale;
            foreach (Child c in mChildren)
            {
                Scale = Constants.GetScale(((ImageSection)c).Size, this.Size);
                c.GenerateSubChildren((int)(Scale * mColorForgive), (int)(Scale * mColorDetail), mMinMargin);
            #if GUIOUTPUT
                Prog += 1d / (double)mChildren.Count() * 0.5d;
            #endif
            }
            #if GUIOUTPUT
            Disp.Close();
            Disp.Dispose();
            t.Dispose();
            #endif
        }