A simple example of C timer timing updates
- 2020-05-26 10:01:11
- OfStack
As follows:
class Program
{
static void Main(string[] args)
{
//for (int i = 0; i < 100; i++)
//{
// SendMessage("13161626306", "13161626306");
//}
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler(aTimer_Elapsed);
// Sets the time interval for the trigger time Set this to 1 second (1000 milliseconds)
aTimer.Interval = 300; // Set the time interval
aTimer.Enabled = true;
Console.WriteLine(" Press enter to end the program ");
Console.WriteLine(" Waiting for the program to execute... ");
Console.ReadLine();
//SendMessage("13161626306", "13161626306");
}
static void aTimer_Elapsed(object sender, ElapsedEventArgs e)
{
SendMessage("13161626306", "13161626306");
}
private static void SendMessage(string PhoneNum, string Message)
{
try
{
using (ServiceReference1.WcfServiceClient sum = new ConsoleApplication1.ServiceReference1.WcfServiceClient())
{
ServiceReference1.MessageOk ok = new ConsoleApplication1.ServiceReference1.MessageOk();
ok.Message = Message;
ok.Phone = PhoneNum;
ServiceReference1.MessageOk NewMessage = sum.Ok(ok);
Console.WriteLine(NewMessage.Message);
Console.WriteLine("22");
//Console.ReadLine();
}
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
Console.ReadKey();
}
}
}