/// <summary> /// Waits for the slots in overwatch to change. /// </summary> /// <param name="maxtime">Time to wait. Set to -1 to wait forever.</param> /// <returns>Returns true if Overwatch's slots changed. Returns false if the time ran out.</returns> public bool WaitForSlotUpdate(int maxtime = 1000) { using (SlotInfo slotInfo = new SlotInfo()) { GetUpdatedSlots(slotInfo); return(WaitForSlotUpdate(slotInfo, maxtime)); } }
/// <summary> /// Gets the slots that have changed. /// </summary> /// <param name="slotInfo">The data of the last scan.</param> /// <param name="slotFlags">Flags for the slots to check.</param> /// <returns>A List of slots that changed.</returns> /// <remarks> /// <para>The returned slots are slots that have been swapped, removed, or added to the game.</para> /// <para>The data of the scan is saved in <paramref name="slotInfo"/>. It is compared to next time it is used with this method. /// A new <see cref="SlotInfo"/> object will return every slot.</para> /// </remarks> /// <seealso cref="SlotInfo"/> public List <int> GetUpdatedSlots(SlotInfo slotInfo, SlotFlags slotFlags = SlotFlags.All) { using (LockHandler.Passive) { object listLock = new object(); List <int> changedSlots = new List <int>(); var slots = GetSlots(slotFlags); for (int slot = 0; slot < SlotCount; slot++) //Parallel.For(0, SlotCount, (slot) => { SlotIdentity slotIdentity = slots.Contains(slot) ? GetSlotIdentity(slot) : null; bool changed = true; // Slot emptied if (slotIdentity == null && slotInfo.SlotIdentities[slot] != null) { slotInfo.SlotIdentities[slot].Dispose(); slotInfo.SlotIdentities[slot] = null; } // Slot joined else if (slotIdentity != null && slotInfo.SlotIdentities[slot] == null) { slotInfo.SlotIdentities[slot] = slotIdentity; } // Slot swapped else if (slotIdentity != null && slotInfo.SlotIdentities[slot] != null && !Identity.Compare(slotInfo.SlotIdentities[slot], slotIdentity)) { slotInfo.SlotIdentities[slot].Dispose(); slotInfo.SlotIdentities[slot] = slotIdentity; } // Slot did not change else { if (slotIdentity != null) { slotIdentity.Dispose(); } changed = false; } if (changed) { lock (listLock) changedSlots.Add(slot); } } return(changedSlots); } }
/// <summary> /// Waits for the slots in overwatch to change. /// </summary> /// <param name="slotInfo">Slot info to compare to.</param> /// <param name="maxtime">Time to wait. Set to -1 to wait forever.</param> /// <returns>Returns true if Overwatch's slots changed. Returns false if the time ran out.</returns> public bool WaitForSlotUpdate(SlotInfo slotInfo, int maxtime = 1000) { using (LockHandler.Passive) { Stopwatch time = new Stopwatch(); time.Start(); while (time.ElapsedMilliseconds < maxtime || maxtime == -1) { if (GetUpdatedSlots(slotInfo).Count > 0) { return(true); } Thread.Sleep(10); } return(false); } }