private async void lnkUpdate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { if (Bot.Player.LoggedIn) { lnkUpdate.Enabled = false; await Task.Run(() => { AutoResetEvent wait = new AutoResetEvent(false); using (StreamWriter writer = new StreamWriter("Quests.txt", true)) { int start = ((QuestData)lbQuests.Items[lbQuests.Items.Count - 1]).ID + 1; for (int i = start; i < 10000; i += 10) { Bot.SetGameObject("world.questTree", new ExpandoObject()); this.CheckedInvoke(() => Text = $"Loading Quests {i}-{i + 10}..."); Bot.Quests.Load(Enumerable.Range(i, 10).ToArray()); List <Quest> quests = new List <Quest>(); void packetListener(ScriptInterface bot, dynamic packet) { if (packet["params"].type == "json" && packet["params"].dataObj.cmd == "getQuests") { ValueCollection col = JsonConvert.DeserializeObject <Dictionary <int, Quest> >(JsonConvert.SerializeObject(packet["params"].dataObj.quests)).Values; quests = col.ToList(); } wait.Set(); } Bot.Events.ExtensionPacketReceived += packetListener; wait.WaitOne(5000); Bot.Events.ExtensionPacketReceived -= packetListener; if (quests.Count == 0) { break; } quests.ForEach(q => writer.WriteLine($"{q.ID}:{q.Name}")); writer.Flush(); Bot.Sleep(1000); } } }); Text = "Reloading list..."; await Task.Run(_UpdateList); Text = "IDs"; lnkUpdate.Enabled = true; } else { MessageBox.Show("You must be logged in to update the quest list."); } }