Click here to Skip to main content
15,904,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

Hi created a ping app, my problem is when it is finished
I want it to display a messagebox when it is finished and if
it run into an error I want it to also display another messagebox.

Here is the code. at the moment it shows it in the output
window. I want it in the messagebox aswell

Please any help would be appriciated..

string IP;
....
IP = txtIPAddr.Text;
            using (Ping ping = new Ping())
            {
                try
                {
                    Console.Write("    {0}...", IP);
                    PingReply reply = ping.Send(IP, 100);
                    if (reply.Status == IPStatus.Success)
                    {
                        Console.WriteLine("Success - IP Address:{0}", reply.Address, reply.RoundtripTime);
                    }
                    else
                    {
                        Console.WriteLine(reply.Status);
                    }
                }

                catch (Exception ex)
                {
                    Console.WriteLine("Error ({0})",
                        ex.InnerException.Message);
                }
            }
Posted
Updated 21-Feb-12 3:43am
v2

1 solution

By the look of it, that is a console app - whiule you can display a message box from a Console app, it isn't really a good idea.

If you must, then:
1) Add a Reference to System.Windows.Forms to your project.
2) Add the line:
C#
using System.Windows.Forms;
To your code.
3) You can now use MessageBox.Show instead of Console.WriteLine.

But it is a much, much better idea to switch to a WinForms app instead.
 
Share this answer
 
Comments
Ben Paxton 21-Feb-12 9:42am    
Yes I did tri this, for some reason in the if/else statement I cant put MessageBox.Show
Shahin Khorshidnia 21-Feb-12 9:53am    
Show MessageBox in another thread

OriginalGriff 21-Feb-12 9:54am    
Why not? What happens?

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