Software Engineer
IFG Management Limited
http://www.ifgint.com
/*******************************************************/
using
System;using
System.Text;using
System.Net;using
System.Timers;public
class Runner{
private const string url = ""; public static void Main(){
RequestTest[] events =
new RequestTest[5]; for(int i = 0; i < 5; i++)events[i] =
new RequestTest(url, 15000, i);Console.WriteLine("Type 'quit' to exit");
Listen:
string input = Console.ReadLine(); if(input == "quit"){
for(int i = 0; i < 5; i++){
events[i].Dispose();
events[i] =
null;}
}
else goto Listen;}
}
public
class RequestTest : IDisposable{
int m_ID;HttpStatusCode m_StatusCode;
string m_ContentType; string m_URL = string.Empty;TimeSpan m_TestDuration =
new TimeSpan(0, 0, 0);System.Timers.Timer m_Timer =
new System.Timers.Timer(); public RequestTest(string url, int interval, int id){
m_ID = id;
m_URL = url;
m_Timer.Elapsed +=
new ElapsedEventHandler(ExecuteRequest);m_Timer.Interval = interval;
m_Timer.AutoReset =
true;m_Timer.Enabled =
true;}
public void ExecuteRequest(object source, ElapsedEventArgs e){
HttpWebRequest request =
null;HttpWebResponse response =
null;DateTime requestStart = DateTime.Now;
try{
Console.WriteLine("{0} - Executing. ID: {1}", DateTime.Now, m_ID);
//create the requestrequest = (HttpWebRequest)WebRequest.Create(m_URL);
request.MaximumAutomaticRedirections = 4;
request.MaximumResponseHeadersLength = 4;
request.Timeout = 10000;
response = (HttpWebResponse)request.GetResponse();
//get the status and content typem_StatusCode = response.StatusCode;
m_ContentType = response.ContentType;
//mark the end of the testm_TestDuration = DateTime.Now - requestStart;
Console.WriteLine("{0} - Completed. ID: {1} Duration: {2}", DateTime.Now, m_ID, m_TestDuration);
}
catch(WebException ex){
//mark the end of the testm_TestDuration = DateTime.Now - requestStart;
Console.WriteLine(
string.Format("{0} - Duration: {1} ID: {2} WebException: {3}",DateTime.Now, m_TestDuration, m_ID, ex.Message));
}
catch(Exception ex){
Console.WriteLine(
string.Format("{0} - Duration: {0} ID: {1} Exception: {2}",DateTime.Now, m_TestDuration, m_ID, ex.Message));
}
finally{
m_StatusCode = 0;
m_ContentType =
string.Empty;request =
null; if(response != null){
response.Close();
response =
null;}
}
}
public void Dispose(){
if(m_Timer != null){
m_Timer.Dispose();
m_Timer =
null;}
}
}
/*******************************************************/
The information contained in this E-mail is confidential. It may also be
legally privileged. It is intended only for the stated addressee(s) and access
to it by any other person is unauthorised. If you are not an addressee, you must
not disclose, copy, circulate or in any other way use or rely on the information
contained in this E-mail. Such unauthorised use may be unlawful. If you have
received this E-mail in error, please inform us immediately and delete it and
all copies from your system.
Due to the fact that this E-mail could become corrupted or altered during
transmission, any advice which it contains should not be relied upon unless
subsequently confirmed by fax or letter signed by or on behalf of this
company.
E-mails do not constitute compliance with any time limits or deadlines.
This e-mail message has been scanned for Viruses and Content and cleared by NetIQ MailMarshal
