public int IndexOf(T value) { var index = -1; var found = false; foreach (var item in items) { index++; if (item.Equals(value)) { found = true; break; } var args = new CancelableListIterationArgs(index); OnIterate(this, args); if (args.Cancel) { break; } Thread.Sleep(300); // intentioanlly impose a delay } if (found) { return(index); } else { return(-1); } }
static void OnIterate(object sender, CancelableListIterationArgs e) { Console.Write(" ."); if (e.Index > 10) { Console.WriteLine("\nOperation was canceled at iteration {0}", e.Index); e.Cancel = true; } }