Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello there,

I have a question...

There's a bug in my application regarding ping with a server.
I used MSDN sample in my project but I ping several servers and I think it's the matter but I have to do this.

So here's what I've done:
I have a refresh function, called in form shown and in button press, it resets my application variables and also should ping with each server it reads for pinging. After each server set, it use MSDN function, so I call it.

The other problem is in application loading where it should download a file, read it, then set a url in it's browser.

I use a thread for that but since it's my first time I don't know how to fix it.
Since I put these functions on thread my application after several second since progress bar loaded fully, hang, and after 5min come to life again.
However one of its button doesn't load, and it's browser still not set.

http://www.4shared.com/file/wGJE2AkO/PingClient-MSDNSample.htm[^]

http://www.4shared.com/file/Pd3MODTu/Multi-Realm_Luncher-for_fix_13.htm[^]
Posted
Updated 13-Sep-10 11:42am
v3
Comments
Dalek Dave 13-Sep-10 9:48am    
Edited to make sense and fix grammar and syntax.

The server applications especially the download threads need all the operating system help that it can get. Try offloading some of your programs and that should fix the download problem. The first problem is about being about to reset a pinging request. The ping in progress can't be reset as quickly as any other form variables.
 
Share this answer
 
Comments
hassan faghihi 13-Sep-10 10:47am    
1.what u mean offload my downloading? can u give me a sample?
2. think same, but dunno how to do it in other way, need to change my code, and i dunno what exactly i should replace, and what put there instead?!

or for example make 10 function that do ping chacking that if one isn't available second do it ... but ...!!!
Hey,

The window basically hangs because you are using the same thread to download the file as well as updating the application.

When you are dealing with background work, it is always recommended to use Thread [^]and invoke the download method from there.

To ping you might use :

MSIL
public static bool IsConnectedToInternet
       {
           get
           {
               Uri url = new Uri("yoururl");
               string pingurl = string.Format("{0}", url.Host);
               string host = pingurl;
               bool result = false;
               Ping p = new Ping();
               try
               {
                   PingReply reply = p.Send(host, 3000);
                   if (reply.Status == IPStatus.Success)
                       return true;
               }
               catch { }
               return result;
           }
       }

:thumbsup:
 
Share this answer
 
Comments
hassan faghihi 13-Sep-10 17:57pm    
so i should make this function twis?
1 for if is connect and resaut, once to see how much is ping?!!

and one more thing, if i call ping several time, it wont mix again ?!
i see your class is diffrent from the MSDN one, what shouldi write here to it give me ping value ... ?!
BTW it's get class , not set class, so how it suppose to return me value?


sry, i'm so noob...
i had friend, but unfortunately he died in accident, and i can't ask him any more... i'm hard to understand things, that's why i ask too many questions
i tried this but gave me error, so i did once per each, egain generate error :'(

public static int Ping(string hostname)
{
Ping ping = new Ping();

PingReply reply = ping.Send(hostname);
if (reply.Status == IPStatus.Success)
{
Console.WriteLine("Address: {0}", reply.Address);
Console.WriteLine("RoundTrip Time: {0}", reply.RoundtripTime);
Console.WriteLine("Time To Live: {0}", reply.Options.Ttl);
Console.WriteLine("Don't Fragment: {0}", reply.Options.DontFragment);
Console.WriteLine("Buffer Size: {0}", reply.Buffer.Length);
Console.WriteLine("Status: {0}", reply.Status);

Console.ReadLine();
return (0);
}
else
{
Console.WriteLine("Error");
Console.WriteLine("Status: {0}", reply.Status);
Console.ReadLine();
return (1);
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900