Click here to Skip to main content
15,850,750 members
Home / Discussions / C#
   

C#

 
Questionrun a method on other application Pin
solomon8528-Aug-10 1:47
solomon8528-Aug-10 1:47 
AnswerRe: run a method on other application Pin
Eddy Vluggen28-Aug-10 4:16
professionalEddy Vluggen28-Aug-10 4:16 
AnswerRe: run a method on other application Pin
dan!sh 28-Aug-10 4:37
professional dan!sh 28-Aug-10 4:37 
AnswerRe: run a method on other application Pin
Abhinav S28-Aug-10 6:26
Abhinav S28-Aug-10 6:26 
QuestionBacking up database file using SMO error Pin
gamer112727-Aug-10 17:52
gamer112727-Aug-10 17:52 
Questionbuilding a win form application problem Pin
mrkeivan27-Aug-10 12:37
mrkeivan27-Aug-10 12:37 
AnswerRe: building a win form application problem Pin
Not Active27-Aug-10 13:01
mentorNot Active27-Aug-10 13:01 
QuestionWin7 No PingCompletedCallback on timeout? Pin
Gavin Coates27-Aug-10 8:44
Gavin Coates27-Aug-10 8:44 
Hey guys,

I wrote a network scanning tool a few years ago, which pings a list of IP addresses. I recently moved to Windows 7, and have noticed some strange behaviour in the program. My ping code is as follows:

public void pingIP(int IP)
        {
            AutoResetEvent waiter = new AutoResetEvent (false);
            string IPaddress = IPpart1.Value.ToString() + "." + IPpart2.Value.ToString() + "." + IPpart3.Value.ToString() + "." + IP;
            IPAddress IPa = IPAddress.Parse(IPaddress);
            
            Debug.WriteLine("Pinging " + IP.ToString());
            
            Ping ping = new Ping();
            ping.PingCompleted += new PingCompletedEventHandler(PingCompletedCallback);

            ping.SendAsync(IPa, waiter);
            
        }


This then calls PingCompletedCallback when it recieves a response:
public  void PingCompletedCallback(object sender, PingCompletedEventArgs e)
        {
            

            PingReply reply = e.Reply;
                // get the IP that was pinged
                string IP = reply.Address.ToString();
                
                if(IP != "0.0.0.0")
                {
	                string[] IParray = IP.Split('.');
	                int iIP = Int32.Parse(IParray[3]);
	                if (reply.Status == IPStatus.Success)
	                    pingResult[iIP] = reply.RoundtripTime.ToString();
	                else
	                    pingResult[iIP] = "X";
	            
	                Debug.WriteLine("Ping Reply From " + IP.ToString() + " Time: " + pingResult[iIP]);
	
	                // check if the last ping (255) has been reveived and mark the ping complete flag if so
	                if (iIP == 255)
	                {
	                    pingComplete = true;
	                    lblStatus.Text = "Ping Complete";
	                }
                }
                
                
                
            ((AutoResetEvent)e.UserState).Set();
        }


Now, under Windows XP this worked fine, PingCompletedCallback was called for every ping I sent - either with a response, or with a timeout. I could then set the value as required. However, under Win7, PingCompletedCallback only seems to be called when a successful response is received. I have also noticed I recieve a lot of replies from "0.0.0.0", as well as multiple replies from the IP the machine is running on (10.0.0.4)

I have a second screen for doing a detailed ping on a single IP, which doesnt use a callback function, and it works fine when no response is received:

public void startPing(IPAddress IP)
        {
            
            
            textStatus.Text += "Pinging " + IP.ToString() + "...";
            this.Refresh();

            Ping ping = new Ping();

            PingReply reply = ping.Send(IP);
            if (reply.Status == IPStatus.Success)
                textStatus.Text += " Time: " + reply.RoundtripTime.ToString() + "\r\n";
            else
                textStatus.Text += reply.Status.ToString() + "\r\n";
        }


Has nayone seen anything like this before? Im a little confused!
QuestionCustom file type Pin
Etienne_12327-Aug-10 6:29
Etienne_12327-Aug-10 6:29 
AnswerRe: Custom file type Pin
OriginalGriff27-Aug-10 6:46
mveOriginalGriff27-Aug-10 6:46 
GeneralRe: Custom file type Pin
Etienne_12327-Aug-10 7:14
Etienne_12327-Aug-10 7:14 
AnswerRe: Custom file type Pin
Chris Trelawny-Ross27-Aug-10 6:47
Chris Trelawny-Ross27-Aug-10 6:47 
AnswerRe: Custom file type Pin
OriginalGriff27-Aug-10 6:51
mveOriginalGriff27-Aug-10 6:51 
GeneralRe: Custom file type Pin
Etienne_12327-Aug-10 7:18
Etienne_12327-Aug-10 7:18 
GeneralRe: Custom file type Pin
OriginalGriff27-Aug-10 9:20
mveOriginalGriff27-Aug-10 9:20 
GeneralRe: Custom file type Pin
Etienne_12327-Aug-10 11:52
Etienne_12327-Aug-10 11:52 
GeneralRe: Custom file type Pin
OriginalGriff27-Aug-10 21:24
mveOriginalGriff27-Aug-10 21:24 
AnswerRe: Custom file type Pin
Kubajzz27-Aug-10 6:52
Kubajzz27-Aug-10 6:52 
AnswerRe: Custom file type Pin
Luc Pattyn27-Aug-10 7:04
sitebuilderLuc Pattyn27-Aug-10 7:04 
GeneralRe: Custom file type Pin
Yusuf27-Aug-10 13:23
Yusuf27-Aug-10 13:23 
GeneralRe: Custom file type Pin
AspDotNetDev27-Aug-10 13:43
protectorAspDotNetDev27-Aug-10 13:43 
GeneralRe: Custom file type Pin
Yusuf27-Aug-10 19:50
Yusuf27-Aug-10 19:50 
GeneralRe: Custom file type Pin
AspDotNetDev27-Aug-10 21:04
protectorAspDotNetDev27-Aug-10 21:04 
AnswerRe: Custom file type Pin
AspDotNetDev27-Aug-10 7:51
protectorAspDotNetDev27-Aug-10 7:51 
AnswerRe: Custom file type Pin
I Believe In GOD27-Aug-10 8:38
I Believe In GOD27-Aug-10 8:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.