public async void execute() { Yandex yandex = new Yandex(); if (!yandex.isValidRegion()) { yandex.open_settings(); } yandex.change_search_pos_count(); try { while (true) { kwMutext.WaitOne(); var globalOffset = !settings.KeyExists("offset", SETTINGS_SECTION) ? long.Parse(settings.Write("offset", "" + offset, SETTINGS_SECTION)) : long.Parse(settings.Read("offset", SETTINGS_SECTION)); this.offset = Math.Max(this.offset, globalOffset); this.limit = STEP; this.offset += this.limit; globalOffset += this.limit; settings.Write("offset", "" + Math.Max(this.offset, globalOffset), SETTINGS_SECTION); List <DBKeyword> list = this.listKeywords(offset, limit); if (list == null) { kwMutext.ReleaseMutex(); break; } kwMutext.ReleaseMutex(); foreach (DBKeyword kw in list) { yandex.search(kw); Thread.Sleep(YandexUtils.rndSleep()); } } }catch { Task.Run(() => (new SelfRestarter(TimeSpan.FromSeconds(25))).execute()); } yandex.exit(); }
public async void execute() { Yandex yandex = new Yandex(); if (!yandex.isValidRegion()) { yandex.open_settings(); } yandex.change_search_pos_count(); try { while (true) { kwMutext.WaitOne(); this.offset = !settings.KeyExists("offset", SETTINGS_SECTION) ? long.Parse(settings.Write("offset", "" + offset, SETTINGS_SECTION)) : long.Parse(settings.Read("offset", SETTINGS_SECTION)); this.limit = STEP; this.offset += this.limit; settings.Write("offset", "" + this.offset, SETTINGS_SECTION); List <DBKeyword> list = this.listKeywords(offset, limit); if (list == null) { kwMutext.ReleaseMutex(); break; } kwMutext.ReleaseMutex(); foreach (DBKeyword kw in list) { yandex.search(kw); Thread.Sleep(YandexUtils.rndSleep()); } } }catch { } yandex.exit(); }