Exemplo n.º 1
0
        BotCycle()
        {
            thread = new Thread(bot_cycle);
            thread.Start();
            object o = ThreadRoutines.WaitForCondition(() => { if (Id < 0)
                                                               {
                                                                   return(null);
                                                               }
                                                               return(Id); }, 100000);

            if (o == null)
            {
                throw new Exception("Could not start BotCycle thread");
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Closes current session: closes session logs if all input Items were processed
 /// </summary>
 public static void Close()
 {
     lock (Log.Main)
     {
         if (This == null)
         {
             return;
         }
         if (This.closing_thread != null)
         {
             return;
         }
         State = SessionState.CLOSING;
         This.Storage.WriteState(State, new { });
         This.closing_thread = ThreadRoutines.Start(This.close);
     }
 }
Exemplo n.º 3
0
        public static object WaitForCondition(this WebBrowser browser, Func <object> check_condition, int timeout_in_mss)
        {
            DateTime timeout = DateTime.Now.AddMilliseconds(timeout_in_mss);

            while (DateTime.Now < timeout)
            {
                object o = null;
                browser.Invoke(() =>
                {
                    if (browser.Document != null && browser.Document.Body != null)
                    {
                        o = check_condition();
                    }
                });
                if (o != null)
                {
                    return(o);
                }
                ThreadRoutines.Wait(20);
            }
            return(null);
        }
Exemplo n.º 4
0
 internal static void Start()
 {
     lock (threads2bot_cycle)//locked until threads2bot_cycle[t] = bc; to have a correct thread number
     {
         if (threads2bot_cycle.Count >= Settings.Engine.MaxBotThreadNumber)
         {
             return;
         }
         BotCycle bc = null;
         Thread   t  = ThreadRoutines.Start(() =>
         {
             bc = Activator.Create <BotCycle>(false);
             bc.bot_cycle();
         }
                                            );
         if (!SleepRoutines.WaitForCondition(() => { return(bc != null && bc.Id >= 0); }, 100000))
         {
             throw new Exception("Could not start BotCycle thread");
         }
         threads2bot_cycle[t] = bc;
     }
 }