BotCycle() { thread = new Thread(bot_cycle); thread.IsBackground = true; thread.Start(); if (!SleepRoutines.WaitForCondition(() => { return(Id >= 0); }, 100000)) { throw new Exception("Could not start BotCycle thread"); } }
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); } SleepRoutines.Wait(20); } return(null); }
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; } }