using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;
using System.Data.SqlClient;
using System.Data;
using System.Timers;
using System.Collections;
using System.Threading;
namespace DeployeeSrv
{
class Program { static SqlConnection connection = new SqlConnection(Properties.Settings.Default.dbConnection); static SqlCommand command = new SqlCommand(); static SqlDataReader Reader = null; static ArrayList al = new ArrayList(); delegate String test(String target);
class Program
static SqlConnection connection = new SqlConnection(Properties.Settings.Default.dbConnection); static SqlCommand command = new SqlCommand(); static SqlDataReader Reader = null; static ArrayList al = new ArrayList(); delegate String test(String target);
static SqlConnection connection = new SqlConnection(Properties.Settings.Default.dbConnection);
static SqlCommand command = new SqlCommand();
static SqlDataReader Reader = null;
static ArrayList al = new ArrayList();
delegate String test(String target);
static void Main(string[] args) { System.Timers.Timer timer = new System.Timers.Timer(); //ad 1: handle Elapsed event timer.Elapsed += new ElapsedEventHandler(OnElapsedTime); timer.Interval = 60000; timer.Enabled = true; timer.Start(); DoWork(); Console.Read(); } public static void DoWork() { al.Clear(); try { connection.Open(); command = connection.CreateCommand(); command.CommandText = "SELECT [target] from [controller].[dbo].[pending_jobs] where [Scheduled] = 0 GROUP BY [target]"; Reader = command.ExecuteReader(); while (Reader.Read()) { //add to the array list al.Add(Reader["target"].ToString()); } Reader.Close(); for (int i = 0; i < al.Count; i++) { command.CommandText = @"UPDATE [dbo].[Pending_Jobs]
static void Main(string[] args)
System.Timers.Timer timer = new System.Timers.Timer(); //ad 1: handle Elapsed event timer.Elapsed += new ElapsedEventHandler(OnElapsedTime); timer.Interval = 60000; timer.Enabled = true; timer.Start(); DoWork(); Console.Read();
System.Timers.Timer timer = new System.Timers.Timer();
//ad 1: handle Elapsed event
timer.Elapsed += new ElapsedEventHandler(OnElapsedTime);
timer.Interval = 60000;
timer.Enabled = true;
timer.Start();
DoWork();
Console.Read();
}
public static void DoWork()
al.Clear(); try { connection.Open(); command = connection.CreateCommand(); command.CommandText = "SELECT [target] from [controller].[dbo].[pending_jobs] where [Scheduled] = 0 GROUP BY [target]"; Reader = command.ExecuteReader(); while (Reader.Read()) { //add to the array list al.Add(Reader["target"].ToString()); } Reader.Close(); for (int i = 0; i < al.Count; i++) { command.CommandText = @"UPDATE [dbo].[Pending_Jobs]
al.Clear();
try
connection.Open(); command = connection.CreateCommand(); command.CommandText = "SELECT [target] from [controller].[dbo].[pending_jobs] where [Scheduled] = 0 GROUP BY [target]"; Reader = command.ExecuteReader(); while (Reader.Read()) { //add to the array list al.Add(Reader["target"].ToString()); } Reader.Close(); for (int i = 0; i < al.Count; i++) { command.CommandText = @"UPDATE [dbo].[Pending_Jobs]
connection.Open();
command = connection.CreateCommand();
command.CommandText = "SELECT [target] from [controller].[dbo].[pending_jobs] where [Scheduled] = 0 GROUP BY [target]";
Reader = command.ExecuteReader();
while (Reader.Read())
//add to the array list al.Add(Reader["target"].ToString());
//add to the array list
al.Add(Reader["target"].ToString());
Reader.Close();
for (int i = 0; i < al.Count; i++)
command.CommandText = @"UPDATE [dbo].[Pending_Jobs]
SET [Scheduled] = 1 WHERE [target] = '" + al[i].ToString() + "' and [Scheduled] = 0 ";
SET [Scheduled] = 1
WHERE [target] = '" + al[i].ToString() + "' and [Scheduled] = 0 ";
command.ExecuteNonQuery(); worker wk = new worker(); // create the delegate test t = new test(wk.dostuff); // call the delegate asynchronously IAsyncResult result = t.BeginInvoke(al[i].ToString(), new AsyncCallback(CallbackMethod), t); } } catch (SqlException ex) { Console.WriteLine(ex.ToString()); } finally { if (connection.State == ConnectionState.Open) { connection.Close(); } } } static void CallbackMethod(IAsyncResult result) { // get the delegate that was used to call that // method test t = (test)result.AsyncState; // get the return value from that method call //String returnValue = t.EndInvoke(result); t.EndInvoke(result); //Console.WriteLine("The result was " + returnValue.ToString()); } private static void OnElapsedTime(object source, ElapsedEventArgs e) { DoWork(); } }
command.ExecuteNonQuery(); worker wk = new worker(); // create the delegate test t = new test(wk.dostuff); // call the delegate asynchronously IAsyncResult result = t.BeginInvoke(al[i].ToString(), new AsyncCallback(CallbackMethod), t); } } catch (SqlException ex) { Console.WriteLine(ex.ToString()); } finally { if (connection.State == ConnectionState.Open) { connection.Close(); } } } static void CallbackMethod(IAsyncResult result) { // get the delegate that was used to call that // method test t = (test)result.AsyncState; // get the return value from that method call //String returnValue = t.EndInvoke(result); t.EndInvoke(result); //Console.WriteLine("The result was " + returnValue.ToString()); } private static void OnElapsedTime(object source, ElapsedEventArgs e) { DoWork(); }
command.ExecuteNonQuery(); worker wk = new worker(); // create the delegate test t = new test(wk.dostuff); // call the delegate asynchronously IAsyncResult result = t.BeginInvoke(al[i].ToString(), new AsyncCallback(CallbackMethod), t); } } catch (SqlException ex) { Console.WriteLine(ex.ToString()); } finally { if (connection.State == ConnectionState.Open) { connection.Close(); } }
command.ExecuteNonQuery(); worker wk = new worker(); // create the delegate test t = new test(wk.dostuff); // call the delegate asynchronously IAsyncResult result = t.BeginInvoke(al[i].ToString(), new AsyncCallback(CallbackMethod), t); }
command.ExecuteNonQuery(); worker wk = new worker(); // create the delegate test t = new test(wk.dostuff); // call the delegate asynchronously IAsyncResult result = t.BeginInvoke(al[i].ToString(), new AsyncCallback(CallbackMethod), t);
command.ExecuteNonQuery();
worker wk = new worker();
// create the delegate
test t = new test(wk.dostuff);
// call the delegate asynchronously
IAsyncResult result = t.BeginInvoke(al[i].ToString(), new AsyncCallback(CallbackMethod), t);
catch (SqlException ex)
Console.WriteLine(ex.ToString());
finally
if (connection.State == ConnectionState.Open) { connection.Close(); }
if (connection.State == ConnectionState.Open)
connection.Close();
static void CallbackMethod(IAsyncResult result)
// get the delegate that was used to call that // method test t = (test)result.AsyncState; // get the return value from that method call //String returnValue = t.EndInvoke(result); t.EndInvoke(result); //Console.WriteLine("The result was " + returnValue.ToString());
// get the delegate that was used to call that
// method
test t = (test)result.AsyncState;
// get the return value from that method call
//String returnValue = t.EndInvoke(result);
t.EndInvoke(result);
//Console.WriteLine("The result was " + returnValue.ToString());
private static void OnElapsedTime(object source, ElapsedEventArgs e)