Esempio n. 1
0
        internal void Run(object ar)
        {
            object[] args = (object[])ar;
            bool check = (bool)args[0];
            if (!check) {
                proxycount = 0;
                goodList = 0;
                badList = 0;

            }

            bool newcheck = (bool)args[1];
            if (newcheck) {
                goodProxy = 0;
                badProxy = 0;

            }
            int Index = 0;
            int lstproxy = listproxy.Count;
            //find progress step

            WorkProcess[] ProcessArr = new WorkProcess[lstproxy];
            Thread[] t = new Thread[lstproxy];

            try
            {
                int i = 0;
                bool Errorparsing = false;

                var tmp ="";

                while (DoneThreads < lstproxy)
                {
                    Debug.WriteLine("Threading ");
                    if (aborted)
                        throw new Exception();
                    while (WorkingThreads < MaxThread && i < lstproxy)
                    {
                        if (aborted)
                            throw new Exception();

                        Errorparsing = false;
                        tmp = listproxy[i];
                        if (check)
                        {
                            try
                            {
                                Index = int.Parse(Regex.Split(tmp, ":@@:")[1]);
                                tmp = Regex.Split(tmp, ":@@:")[0];

                            }
                            catch
                            {

                                Debug.WriteLine("Error parsing");
                                DoneThreads = 1;
                                Errorparsing = true;

                            }
                        }
                        if (!Errorparsing)
                        {

                            ProcessArr[i] = new WorkProcess(this);

                            t[i] = new Thread(new ParameterizedThreadStart(ProcessArr[i].AsyncScrape))
                            {
                                IsBackground = true,
                                 Priority = ThreadPriority.Lowest

                            };
                            t[i].SetApartmentState(ApartmentState.MTA);

                            WorkingThreads = 1;
                           t[i].Start(new object[] { tmp, t[i].ManagedThreadId, check, Index });

                            Thread.Sleep(100);

                        }
                        i++;
                        if (WorkingThreads == MaxThread)
                        {

                            break;
                        }

                    }//end while workingcount <=maxthread
                    if (WorkingThreads == MaxThread)
                    {

                        _doneEvent.WaitOne();
                        _doneEvent.Reset();
                        Thread.Sleep(1000);
                    }
                    if (i == listproxy.Count) {

                        _allEvent.WaitOne();
                    }

                }//end while donethread < listproxy.length

            }
            catch (ThreadAbortException)
            {

                Thread.ResetAbort();
                Debug.WriteLine("Abort not done");

            }
            catch (ObjectDisposedException e) {
                Debug.WriteLine(e.Message);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);

            }
            if (aborted) {
               for (int i = 0; i < ProcessArr.Length;i++ )
               {
                        if(ProcessArr[i] != null)
                                ProcessArr[i].Abort();

                }
            }
            Debug.WriteLine("Thread fINISHED");

            if (check)
            {
                Parent.savelistviewiptodb(Parent.TabelName[4]);
            }
                foreach (Thread ta in t)
                {
                    if(ta !=null)
                        if(ta.IsAlive)
                            ta.Interrupt();
                }

                MinimizeFootprint();
                finished = true;
                Parent.SetBar(true);

                Thread.Sleep(1000);
                if (check)
                {
                    Parent.SetButton1Text(new object[] { Parent.button11, "Start" });
                }
                else
                {
                    Parent.SetButton1Text(new object[] { Parent.button1, "Start" });
                }

               // Parent.ResetTime();
        }
Esempio n. 2
0
        internal void Run(object ar)
        {
            object[] args  = (object[])ar;
            bool     check = (bool)args[0];

            if (!check)
            {
                proxycount = 0;
                goodList   = 0;
                badList    = 0;
            }

            bool newcheck = (bool)args[1];

            if (newcheck)
            {
                goodProxy = 0;
                badProxy  = 0;
            }
            int Index    = 0;
            int lstproxy = listproxy.Count;

            //find progress step



            WorkProcess[] ProcessArr = new WorkProcess[lstproxy];
            Thread[]      t          = new Thread[lstproxy];

            try
            {
                int  i            = 0;
                bool Errorparsing = false;

                var tmp = "";

                while (DoneThreads < lstproxy)
                {
                    Debug.WriteLine("Threading ");
                    if (aborted)
                    {
                        throw new Exception();
                    }
                    while (WorkingThreads < MaxThread && i < lstproxy)
                    {
                        if (aborted)
                        {
                            throw new Exception();
                        }


                        Errorparsing = false;
                        tmp          = listproxy[i];
                        if (check)
                        {
                            try
                            {
                                Index = int.Parse(Regex.Split(tmp, ":@@:")[1]);
                                tmp   = Regex.Split(tmp, ":@@:")[0];
                            }
                            catch
                            {
                                Debug.WriteLine("Error parsing");
                                DoneThreads  = 1;
                                Errorparsing = true;
                            }
                        }
                        if (!Errorparsing)
                        {
                            ProcessArr[i] = new WorkProcess(this);


                            t[i] = new Thread(new ParameterizedThreadStart(ProcessArr[i].AsyncScrape))
                            {
                                IsBackground = true,
                                Priority     = ThreadPriority.Lowest
                            };
                            t[i].SetApartmentState(ApartmentState.MTA);

                            WorkingThreads = 1;
                            t[i].Start(new object[] { tmp, t[i].ManagedThreadId, check, Index });

                            Thread.Sleep(100);
                        }
                        i++;
                        if (WorkingThreads == MaxThread)
                        {
                            break;
                        }
                    }//end while workingcount <=maxthread
                    if (WorkingThreads == MaxThread)
                    {
                        _doneEvent.WaitOne();
                        _doneEvent.Reset();
                        Thread.Sleep(1000);
                    }
                    if (i == listproxy.Count)
                    {
                        _allEvent.WaitOne();
                    }
                }//end while donethread < listproxy.length
            }
            catch (ThreadAbortException)
            {
                Thread.ResetAbort();
                Debug.WriteLine("Abort not done");
            }
            catch (ObjectDisposedException e) {
                Debug.WriteLine(e.Message);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
            if (aborted)
            {
                for (int i = 0; i < ProcessArr.Length; i++)
                {
                    if (ProcessArr[i] != null)
                    {
                        ProcessArr[i].Abort();
                    }
                }
            }
            Debug.WriteLine("Thread fINISHED");

            if (check)
            {
                Parent.savelistviewiptodb(Parent.TabelName[4]);
            }
            foreach (Thread ta in t)
            {
                if (ta != null)
                {
                    if (ta.IsAlive)
                    {
                        ta.Interrupt();
                    }
                }
            }

            MinimizeFootprint();
            finished = true;
            Parent.SetBar(true);

            Thread.Sleep(1000);
            if (check)
            {
                Parent.SetButton1Text(new object[] { Parent.button11, "Start" });
            }
            else
            {
                Parent.SetButton1Text(new object[] { Parent.button1, "Start" });
            }

            // Parent.ResetTime();
        }