static void ThreadGetStepKey() { while (true) { while (!servicePaused) { try { DataSet ds = new DataSet(); List <string> lstNewKey = new List <string>(); ds = isof.CreateIWipJobAutoTrack().GetWaitingForTrackOutJobs(); if (ds != null && ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { lstNewKey.Add(ds.Tables[0].Rows[i]["ROW_KEY"].ToString()); } var resint = lstNewKey.Except(lstKey); foreach (string item in resint) { string a = item; lock (lstKey) { lstKey.Add(a); } ThreadPool.QueueUserWorkItem(new WaitCallback(DoWork), a); Thread.Sleep(1000); } } } catch (Exception ex) { Thread threadError = new Thread(new ParameterizedThreadStart(LogService.LogError)); threadError.Start(ex); } Thread.Sleep(AutoTrackTime); } } }