public Bug[] GetBugsForProduct(string product, string[] statuses, string[] severities, DateTime changedSince, ProgressCallback progressCallback) { List <Bug> res = new List <Bug> (); int queries = statuses.Length * severities.Length; progressCallback(queries, 0); int work = 0; Exception error = null; foreach (string st in statuses) { foreach (string sv in severities) { string status = st; string severity = sv; ThreadStart ts = delegate { BugSearchForProduct param = new BugSearchForProduct(); param.status = status; param.severity = severity; param.product = product; param.last_change_time = ToTimeString(changedSince); Console.WriteLine("querying: " + severity + " " + status); try { BugInfo[] bis = Proxy.Search(param).bugs; lock (res) { foreach (BugInfo bi in bis) { res.Add(new Bug(this, bi)); } } } catch (Exception ex) { error = ex; } finally { lock (res) { queries--; System.Threading.Monitor.Pulse(res); Console.WriteLine("done querying: " + severity + " " + status + " Q:" + queries); } } progressCallback(queries, ++work); }; Thread t = new Thread(ts); t.IsBackground = true; t.Start(); } } lock (res) { while (queries > 0) { System.Threading.Monitor.Wait(res); } } if (error != null) { throw error; } return(res.ToArray()); }
public Bug[] GetBugsForProduct(string product, string[] statuses, string[] severities, DateTime changedSince, ProgressCallback progressCallback) { List<Bug> res = new List<Bug> (); int queries = statuses.Length * severities.Length; progressCallback (queries, 0); int work = 0; Exception error = null; foreach (string st in statuses) { foreach (string sv in severities) { string status = st; string severity = sv; ThreadStart ts = delegate { BugSearchForProduct param = new BugSearchForProduct (); param.status = status; param.severity = severity; param.product = product; param.last_change_time = ToTimeString (changedSince); Console.WriteLine ("querying: " + severity + " " + status); try { BugInfo[] bis = Proxy.Search (param).bugs; lock (res) { foreach (BugInfo bi in bis) res.Add (new Bug (this, bi)); } } catch (Exception ex) { error = ex; } finally { lock (res) { queries--; System.Threading.Monitor.Pulse (res); Console.WriteLine ("done querying: " + severity + " " + status + " Q:" + queries); } } progressCallback (queries, ++work); }; Thread t = new Thread (ts); t.IsBackground = true; t.Start (); } } lock (res) { while (queries > 0) System.Threading.Monitor.Wait (res); } if (error != null) throw error; return res.ToArray (); }