public AdList() { olock = new object(); Links = new List <AdLink>(); Pointer = null; HasRound = false; }
public void Update(AdLink old, string neww) { //AdLink item = AdList.Find(a => a != null && !a.isRemoved && a.linkstring.Equals(old)); if (old != null && neww != null) { AdLink.Update(old, neww); } //item = new AdLink(neww); }
private byte[] getNext() { AdLink item = AdList.GetNext(); if (item != null) { return(item.linkbytes); } else { return(null); } }
private void Next() { lock (olock) { if (Pointer == null) { if (Links.Count > 0) { Pointer = Links.First(); // gets first obj } } else// if(Pointer != null) { if (Links.Last() == Pointer) // last index pointer. Call GC and reset pointer { HasRound = true; if (Links.Count > 1) { Links.RemoveAll(l => l.isRemoved); // can't call GC inside of locked object, -----> DeadLock Fixed <----- } //GC(); //Pointer = Links.FirstOrDefault(); // works too, but i dont use it here if (Links.Count > 0) { Pointer = Links.First(); // can be null element, but np } else { Pointer = null; } } else { int index = Links.IndexOf(Pointer); if (index < 0 || index + 1 >= Count) // Dafuq.. this case isn't allowed to trigger! { return; } Pointer = Links[index + 1]; } } } }
/*public void Remove(AdLink link) * { * // AdLink ad = Find(l => l.linkstring.Equals(link)); * if (link != null) * Remove(link); * }*/ public void Remove(AdLink link) { // lock here? Yes, Client's Thread might access obj onError Event lock (olock) link.Remove(); }
/*public AdLink Last * { * get * { * lock (olock) * return Links.Last(); * } * } * * public AdLink First * { * get * { * lock (olock) * return Links.First(); * } * }*/ public void Add(AdLink link) { lock (olock) Links.Add(link); }
public void MarkAsRemoved(AdLink link) { AdList.Remove(link); }
public void AddToNext(AdLink link) // some sync needed here! { lock (olock) NextList.Add(link); }
public static void Update(AdLink old, string nw) { old.linkstring = nw; old.linkbytes = System.Text.ASCIIEncoding.UTF8.GetBytes(nw); }