T
Theepan123
Guest
<g class="gr_ gr_152 gr-alert gr_gramm gr_inline_cards gr_disable_anim_appear Punctuation only-ins replaceWithoutSep" data-gr-id="152" id="152">Hi</g> I have Project call List of IP addresses need to pinging and then reply status that those <g class="gr_ gr_143 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling ins-del multiReplace" data-gr-id="143" id="143">ip</g> address using the timer.
<g class="gr_ gr_298 gr-alert gr_tiny gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling multiReplace" data-gr-id="298" id="298">i</g> am done with the project but the issue is when the run long time for example 12 hours Object reference error
Here the code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Configuration;
using System.Net.NetworkInformation;
using System.Collections.Specialized;
using System.Configuration;
using Qlib;
using System.IO;
using System.Timers;
using System.Windows.Forms;
using System.Threading;
namespace PingAddress
{
public partial class Form1 : Form
{
string Ip_address_value;
PingReply rep_ipaddress;
System.Timers.Timer time;
Ping pingasync;
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
public Form1()
{
key.SetValue("IP Address ping ",Application.ExecutablePath.ToString());
InitializeComponent();
Qlib.Logger.SolutionName = "Ping Information";
Qlib.Logger.SubprojectName = "Ping Qlog";
try
{
if (ConfigurationManager.AppSettings["log"] == "on")
{
Logger.EnableLogging = true;
}
Logger.Log("logger is Started");
}
catch (Exception e)
{
Logger.Log("Qlib Exception:" + e.Message);
}
}
private void Form1_Load(object sender, EventArgs e)
{
time = new System.Timers.Timer();
time.Elapsed += Time_Elapsed;
time.Interval = 5000;
time.Enabled = true;
time.AutoReset = true;
//PingIp(Ip_address_value);
//Thread tid1 = new Thread(new ThreadStart(Thread1));
//ThreadPool.QueueUserWorkItem(ThreadProc)
//tid1.Start();
//tid1.IsBackground = true;
//hread.Sleep(5000);
//ThreadPool.QueueUserWorkItem(ThreadProc);
//tid1.IsBackground
this.Hide();
}
private void Time_Elapsed(object sender, ElapsedEventArgs e)
{
time.Stop();
//PingIp(Ip_address_value);
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
Qlib.Logger.Log("config:" + config);
ConfigurationSectionGroup fileCheckersGroup = config.SectionGroups["FileCheckers"];
Qlib.Logger.Log("fileCheckersGroup:" + fileCheckersGroup);
foreach (ConfigurationSection section in fileCheckersGroup.Sections)
{
NameValueCollection sectionSettings = ConfigurationManager.GetSection(section.SectionInformation.SectionName) as NameValueCollection;
Qlib.Logger.Log("sectionSettings:" + sectionSettings);
Ip_address_value = sectionSettings["IPAddress"];
Qlib.Logger.Log("Ip_address_value:" + Ip_address_value);
//PingIp(Ip_address_value);
Qlib.Logger.Log("Ip_address_value:" + Ip_address_value);
Ping myPing = new Ping();
PingIp(Ip_address_value);
System.Threading.Thread.Sleep(4000);
notifyIcon1.Icon = SystemIcons.Application;
notifyIcon1.Text = rep_ipaddress.Address.ToString();
Qlib.Logger.Log("IP address:-" + rep_ipaddress);
notifyIcon1.Visible = true;
//Qlib.Logger.Log("notifyIcon1.Visible");
notifyIcon1.BalloonTipTitle = "Welcome IpStatus:-Your Ip Is:-" + rep_ipaddress.Address;
Qlib.Logger.Log("Ip Address:" + rep_ipaddress.Address);
notifyIcon1.BalloonTipText = "Reply From { 0}:bytes ={ 3} ,time = { 1},TTL ={ 2}" + rep_ipaddress.Address.ToString() + " " + rep_ipaddress.RoundtripTime + " " + rep_ipaddress.Options.Ttl + "" + rep_ipaddress.Buffer.Length;
//Qlib.Logger.Log("BalloonTipText");
notifyIcon1.ShowBalloonTip(100);
Qlib.Logger.Log("Success");
Qlib.Logger.Log("------Success END----");
System.Threading.Thread.Sleep(2000);
}
time.Start();
}
//void ThreadProc(Object stateInfo)
//{
// Thread1();
//}
//public void Thread1()
//{
// Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
// Qlib.Logger.Log("config:" + config);
// ConfigurationSectionGroup fileCheckersGroup = config.SectionGroups["FileCheckers"];
// Qlib.Logger.Log("fileCheckersGroup:" + fileCheckersGroup);
// foreach (ConfigurationSection section in fileCheckersGroup.Sections)
// {
// NameValueCollection sectionSettings = ConfigurationManager.GetSection(section.SectionInformation.SectionName) as NameValueCollection;
// Qlib.Logger.Log("sectionSettings:" + sectionSettings);
// Ip_address_value = sectionSettings["IPAddress"];
// Qlib.Logger.Log("Ip_address_value:" + Ip_address_value);
// //PingIp(Ip_address_value);
// Qlib.Logger.Log("Ip_address_value:" + Ip_address_value);
// Ping myPing = new Ping();
// PingIp(Ip_address_value);
// System.Threading.Thread.Sleep(4000);
// notifyIcon1.Icon = SystemIcons.Application;
// pingasync = new Ping();
// PingReply rep_ipaddress = pingasync.Send(Ip_address_value, 3000);
// notifyIcon1.Text = rep_ipaddress.Address.ToString();
// Qlib.Logger.Log("IP address:-" + rep_ipaddress);
// notifyIcon1.Visible = true;
// //Qlib.Logger.Log("notifyIcon1.Visible");
// notifyIcon1.BalloonTipTitle = "Welcome IpStatus:-Your Ip Is:-" + rep_ipaddress.Address;
// Qlib.Logger.Log("Ip Address:" + rep_ipaddress.Address);
// notifyIcon1.BalloonTipText = "Reply From { 0}:bytes ={ 3} ,time = { 1},TTL ={ 2}" + rep_ipaddress.Address.ToString() + " " + rep_ipaddress.RoundtripTime + " " + rep_ipaddress.Options.Ttl + "" + rep_ipaddress.Buffer.Length;
// //Qlib.Logger.Log("BalloonTipText");
// notifyIcon1.ShowBalloonTip(100);
// Qlib.Logger.Log("Success");
// Qlib.Logger.Log("------Success END----");
// System.Threading.Thread.Sleep(2000);
// }
}
private void PingIp(string ip)
{
PingReply rep_ipaddress;
try
{
pingasync = new Ping();
rep_ipaddress = pingasync.Send(ip, 3000);
Qlib.Logger.Log("IP address:-" + rep_ipaddress);
if (rep_ipaddress != null)
{
Qlib.Logger.Log("IP address:-" + ip);
Qlib.Logger.Log("rep_ipaddress:-" + rep_ipaddress);
var pingSender = new Ping();
string data = Encoding.ASCII.GetString(rep_ipaddress.Buffer);
byte[] buffer = Encoding.ASCII.GetBytes(data);
notifyIcon1.Icon = SystemIcons.Application;
notifyIcon1.Text = rep_ipaddress.Address.ToString();
Qlib.Logger.Log("IP Address:-" + rep_ipaddress);
notifyIcon1.Visible = true;
notifyIcon1.BalloonTipTitle = "Pinging:-" + rep_ipaddress.Address + " " + "with 32 bytes of data";
Qlib.Logger.Log("Pinging:-" + rep_ipaddress.Address);
notifyIcon1.BalloonTipText = "Reply From {0} :" + "" + rep_ipaddress.Address.ToString() + ":" + "bytes ={2}:" + rep_ipaddress.Buffer.Length + "Time = {2}" + "" + rep_ipaddress.RoundtripTime + "ms" + "" + "TTL ={3}" + "" + rep_ipaddress.Options.Ttl;
Qlib.Logger.Log("Reply From :-" + rep_ipaddress.Address);
notifyIcon1.ShowBalloonTip(100);
Qlib.Logger.Log("------Success END----");
}
else
{
Qlib.Logger.Log("Ip address is null");
}
}
catch(Exception ex)
{
Qlib.Logger.Log("------Exception----:-"+ex.Message);
Qlib.Logger.Log(ex.Source);
Qlib.Logger.Log(ex.StackTrace);
Qlib.Logger.Log(ex.Message);
notifyIcon1.Icon = SystemIcons.Application;
// notifyIcon1.Text = rep_ipaddress.Address.ToString();
//Qlib.Logger.Log(" notifyIcon1.Visible");
notifyIcon1.Visible = true;
//Qlib.Logger.Log("notifyIcon1.Visible");
// notifyIcon1.BalloonTipTitle = "IpStatus TimeOut:-" + rep_ipaddress.Address;
// Qlib.Logger.Log("IpStatus TimeOut:-"+rep_ipaddress.Address);
notifyIcon1.BalloonTipText = "Status Error:-" + "Please Check Your Ip Address it seems to be this address invalid";
// Qlib.Logger.Log("notifyIcon1.Visible");
notifyIcon1.ShowBalloonTip(100);
Qlib.Logger.Log("------Exception END----");
// PingIp(Ip_address_value);
}
}
//protected void Displaynotify()
//{
// try
// {
// }
// catch (Exception ex)
// {
// System.Timers.Timer time1 = new System.Timers.Timer();
// // time1.Elapsed += Time1_Elapsed;
// time1.Interval = 5000;
// // And start it
// time1.Enabled = true;
// }
//}
//private void Time1_Elapsed(object sender, ElapsedEventArgs e)
//{
// Qlib.Logger.Log("------Exception----");
// notifyIcon1.Icon = SystemIcons.Application;
// notifyIcon1.Text = rep_ipaddress.Address.ToString();
// Qlib.Logger.Log(" notifyIcon1.Visible");
// notifyIcon1.Visible = true;
// Qlib.Logger.Log("notifyIcon1.Visible");
// notifyIcon1.BalloonTipTitle = "IpStatus TimeOut";
// Qlib.Logger.Log(" notifyIcon1.Visible");
// notifyIcon1.BalloonTipText = "Status Error";
// Qlib.Logger.Log(" notifyIcon1.Visible");
// notifyIcon1.ShowBalloonTip(100);
// Qlib.Logger.Log("------Exception END----");
//}
}
}
kandeepan
Continue reading...
<g class="gr_ gr_298 gr-alert gr_tiny gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling multiReplace" data-gr-id="298" id="298">i</g> am done with the project but the issue is when the run long time for example 12 hours Object reference error
Here the code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Configuration;
using System.Net.NetworkInformation;
using System.Collections.Specialized;
using System.Configuration;
using Qlib;
using System.IO;
using System.Timers;
using System.Windows.Forms;
using System.Threading;
namespace PingAddress
{
public partial class Form1 : Form
{
string Ip_address_value;
PingReply rep_ipaddress;
System.Timers.Timer time;
Ping pingasync;
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
public Form1()
{
key.SetValue("IP Address ping ",Application.ExecutablePath.ToString());
InitializeComponent();
Qlib.Logger.SolutionName = "Ping Information";
Qlib.Logger.SubprojectName = "Ping Qlog";
try
{
if (ConfigurationManager.AppSettings["log"] == "on")
{
Logger.EnableLogging = true;
}
Logger.Log("logger is Started");
}
catch (Exception e)
{
Logger.Log("Qlib Exception:" + e.Message);
}
}
private void Form1_Load(object sender, EventArgs e)
{
time = new System.Timers.Timer();
time.Elapsed += Time_Elapsed;
time.Interval = 5000;
time.Enabled = true;
time.AutoReset = true;
//PingIp(Ip_address_value);
//Thread tid1 = new Thread(new ThreadStart(Thread1));
//ThreadPool.QueueUserWorkItem(ThreadProc)
//tid1.Start();
//tid1.IsBackground = true;
//hread.Sleep(5000);
//ThreadPool.QueueUserWorkItem(ThreadProc);
//tid1.IsBackground
this.Hide();
}
private void Time_Elapsed(object sender, ElapsedEventArgs e)
{
time.Stop();
//PingIp(Ip_address_value);
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
Qlib.Logger.Log("config:" + config);
ConfigurationSectionGroup fileCheckersGroup = config.SectionGroups["FileCheckers"];
Qlib.Logger.Log("fileCheckersGroup:" + fileCheckersGroup);
foreach (ConfigurationSection section in fileCheckersGroup.Sections)
{
NameValueCollection sectionSettings = ConfigurationManager.GetSection(section.SectionInformation.SectionName) as NameValueCollection;
Qlib.Logger.Log("sectionSettings:" + sectionSettings);
Ip_address_value = sectionSettings["IPAddress"];
Qlib.Logger.Log("Ip_address_value:" + Ip_address_value);
//PingIp(Ip_address_value);
Qlib.Logger.Log("Ip_address_value:" + Ip_address_value);
Ping myPing = new Ping();
PingIp(Ip_address_value);
System.Threading.Thread.Sleep(4000);
notifyIcon1.Icon = SystemIcons.Application;
notifyIcon1.Text = rep_ipaddress.Address.ToString();
Qlib.Logger.Log("IP address:-" + rep_ipaddress);
notifyIcon1.Visible = true;
//Qlib.Logger.Log("notifyIcon1.Visible");
notifyIcon1.BalloonTipTitle = "Welcome IpStatus:-Your Ip Is:-" + rep_ipaddress.Address;
Qlib.Logger.Log("Ip Address:" + rep_ipaddress.Address);
notifyIcon1.BalloonTipText = "Reply From { 0}:bytes ={ 3} ,time = { 1},TTL ={ 2}" + rep_ipaddress.Address.ToString() + " " + rep_ipaddress.RoundtripTime + " " + rep_ipaddress.Options.Ttl + "" + rep_ipaddress.Buffer.Length;
//Qlib.Logger.Log("BalloonTipText");
notifyIcon1.ShowBalloonTip(100);
Qlib.Logger.Log("Success");
Qlib.Logger.Log("------Success END----");
System.Threading.Thread.Sleep(2000);
}
time.Start();
}
//void ThreadProc(Object stateInfo)
//{
// Thread1();
//}
//public void Thread1()
//{
// Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
// Qlib.Logger.Log("config:" + config);
// ConfigurationSectionGroup fileCheckersGroup = config.SectionGroups["FileCheckers"];
// Qlib.Logger.Log("fileCheckersGroup:" + fileCheckersGroup);
// foreach (ConfigurationSection section in fileCheckersGroup.Sections)
// {
// NameValueCollection sectionSettings = ConfigurationManager.GetSection(section.SectionInformation.SectionName) as NameValueCollection;
// Qlib.Logger.Log("sectionSettings:" + sectionSettings);
// Ip_address_value = sectionSettings["IPAddress"];
// Qlib.Logger.Log("Ip_address_value:" + Ip_address_value);
// //PingIp(Ip_address_value);
// Qlib.Logger.Log("Ip_address_value:" + Ip_address_value);
// Ping myPing = new Ping();
// PingIp(Ip_address_value);
// System.Threading.Thread.Sleep(4000);
// notifyIcon1.Icon = SystemIcons.Application;
// pingasync = new Ping();
// PingReply rep_ipaddress = pingasync.Send(Ip_address_value, 3000);
// notifyIcon1.Text = rep_ipaddress.Address.ToString();
// Qlib.Logger.Log("IP address:-" + rep_ipaddress);
// notifyIcon1.Visible = true;
// //Qlib.Logger.Log("notifyIcon1.Visible");
// notifyIcon1.BalloonTipTitle = "Welcome IpStatus:-Your Ip Is:-" + rep_ipaddress.Address;
// Qlib.Logger.Log("Ip Address:" + rep_ipaddress.Address);
// notifyIcon1.BalloonTipText = "Reply From { 0}:bytes ={ 3} ,time = { 1},TTL ={ 2}" + rep_ipaddress.Address.ToString() + " " + rep_ipaddress.RoundtripTime + " " + rep_ipaddress.Options.Ttl + "" + rep_ipaddress.Buffer.Length;
// //Qlib.Logger.Log("BalloonTipText");
// notifyIcon1.ShowBalloonTip(100);
// Qlib.Logger.Log("Success");
// Qlib.Logger.Log("------Success END----");
// System.Threading.Thread.Sleep(2000);
// }
}
private void PingIp(string ip)
{
PingReply rep_ipaddress;
try
{
pingasync = new Ping();
rep_ipaddress = pingasync.Send(ip, 3000);
Qlib.Logger.Log("IP address:-" + rep_ipaddress);
if (rep_ipaddress != null)
{
Qlib.Logger.Log("IP address:-" + ip);
Qlib.Logger.Log("rep_ipaddress:-" + rep_ipaddress);
var pingSender = new Ping();
string data = Encoding.ASCII.GetString(rep_ipaddress.Buffer);
byte[] buffer = Encoding.ASCII.GetBytes(data);
notifyIcon1.Icon = SystemIcons.Application;
notifyIcon1.Text = rep_ipaddress.Address.ToString();
Qlib.Logger.Log("IP Address:-" + rep_ipaddress);
notifyIcon1.Visible = true;
notifyIcon1.BalloonTipTitle = "Pinging:-" + rep_ipaddress.Address + " " + "with 32 bytes of data";
Qlib.Logger.Log("Pinging:-" + rep_ipaddress.Address);
notifyIcon1.BalloonTipText = "Reply From {0} :" + "" + rep_ipaddress.Address.ToString() + ":" + "bytes ={2}:" + rep_ipaddress.Buffer.Length + "Time = {2}" + "" + rep_ipaddress.RoundtripTime + "ms" + "" + "TTL ={3}" + "" + rep_ipaddress.Options.Ttl;
Qlib.Logger.Log("Reply From :-" + rep_ipaddress.Address);
notifyIcon1.ShowBalloonTip(100);
Qlib.Logger.Log("------Success END----");
}
else
{
Qlib.Logger.Log("Ip address is null");
}
}
catch(Exception ex)
{
Qlib.Logger.Log("------Exception----:-"+ex.Message);
Qlib.Logger.Log(ex.Source);
Qlib.Logger.Log(ex.StackTrace);
Qlib.Logger.Log(ex.Message);
notifyIcon1.Icon = SystemIcons.Application;
// notifyIcon1.Text = rep_ipaddress.Address.ToString();
//Qlib.Logger.Log(" notifyIcon1.Visible");
notifyIcon1.Visible = true;
//Qlib.Logger.Log("notifyIcon1.Visible");
// notifyIcon1.BalloonTipTitle = "IpStatus TimeOut:-" + rep_ipaddress.Address;
// Qlib.Logger.Log("IpStatus TimeOut:-"+rep_ipaddress.Address);
notifyIcon1.BalloonTipText = "Status Error:-" + "Please Check Your Ip Address it seems to be this address invalid";
// Qlib.Logger.Log("notifyIcon1.Visible");
notifyIcon1.ShowBalloonTip(100);
Qlib.Logger.Log("------Exception END----");
// PingIp(Ip_address_value);
}
}
//protected void Displaynotify()
//{
// try
// {
// }
// catch (Exception ex)
// {
// System.Timers.Timer time1 = new System.Timers.Timer();
// // time1.Elapsed += Time1_Elapsed;
// time1.Interval = 5000;
// // And start it
// time1.Enabled = true;
// }
//}
//private void Time1_Elapsed(object sender, ElapsedEventArgs e)
//{
// Qlib.Logger.Log("------Exception----");
// notifyIcon1.Icon = SystemIcons.Application;
// notifyIcon1.Text = rep_ipaddress.Address.ToString();
// Qlib.Logger.Log(" notifyIcon1.Visible");
// notifyIcon1.Visible = true;
// Qlib.Logger.Log("notifyIcon1.Visible");
// notifyIcon1.BalloonTipTitle = "IpStatus TimeOut";
// Qlib.Logger.Log(" notifyIcon1.Visible");
// notifyIcon1.BalloonTipText = "Status Error";
// Qlib.Logger.Log(" notifyIcon1.Visible");
// notifyIcon1.ShowBalloonTip(100);
// Qlib.Logger.Log("------Exception END----");
//}
}
}
kandeepan
Continue reading...