.NET Diary

March 19, 2013

C# .NET Split Function : Inputs – source word and spliter and return – string array

Filed under: All, ASP.NET, C# — leoullas @ 2:36 pm

internal string[] Split(string sourceWord, char[] splitter)
{
string[] retWords = sourceWord.Split(splitter);
return retWords;
}

Advertisements

Ping Server from .NET C# Application to check up/down status

Filed under: All, C# — Tags: — leoullas @ 2:33 pm

internal bool PingServer(string IpAddress)
{
string strDot = “.”;
string[] retWords = Split(IpAddress, strDot.ToCharArray());

bool netOK = false;

byte[] AddrBytes = new byte[] { Convert.ToByte(retWords[0]),
Convert.ToByte(retWords[1]),
Convert.ToByte(retWords[2]),
Convert.ToByte(retWords[3]) }; // byte array for server address.

using (System.Net.NetworkInformation.Ping png = new System.Net.NetworkInformation.Ping())
{
System.Net.IPAddress addr;

addr = new System.Net.IPAddress(AddrBytes);

try
{
netOK = (png.Send(addr, 1500, new byte[] { 0, 1, 2, 3 }).Status == IPStatus.Success);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
netOK = false;
}
return netOK;
}
}

 

internal string[] Split(string sourceWord, char[] splitter)
{
string[] retWords = sourceWord.Split(splitter);
return retWords;
}

BackgroundWorker : The basics

Filed under: All, C# — leoullas @ 2:29 pm

1. Add in your Windows form:

Tools -> backgroundWorker1

2. Event: Introduce the activities in the event “backgroundWorker1_DoWork”

In my Start Process GUI button click, I am calling the followings to start the back process.

blStopBackTrackProcess = false;
backgroundWorker1.RunWorkerAsync();

Then, I have written a non-stop continuous process which is breaking on a boolean value change on my Stop Process GUI button click event.

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{

while (1==1){

Thread.Sleep(DRLib.ClConstants.Check_Interval_Second * 1000);
MessageBox.Show(“abcd” );
CheckNormalServers();

if (blStopBackTrackProcess == true)
break;
}
}

Create a free website or blog at WordPress.com.

%d bloggers like this: