Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7763125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:35:10+00:00 2026-06-01T14:35:10+00:00

I am building a C# windows form app that pings multiple computers by name,

  • 0

I am building a C# windows form app that pings multiple computers by name, which the user can specify.

I am using the System.Net.NetworkInformation.Ping class and the SendAsync method, with a method to handle the result.

The issue I am having occurs when the user specifies a computer name which does not exist. Rather than Ping returning an error to my callback method, however, I get a TargetInvocationException at Application.Run(new Form()) (the main method of the entire form). I have tried surrounding relevant code with try/catch but they never seem to catch the exception

Here is relevant code for ping:

Ping p = null;
try
{
    p = new Ping();
    p.PingCompleted += new PingCompletedEventHandler (updateUI);
    p.SendAsync(computername, 10, computername);
}
    catch (Exception)
{
    ((IDisposable)p).Dispose();
    MessageBox.Show("Ping Failed...");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:35:12+00:00Added an answer on June 1, 2026 at 2:35 pm

    Check the e.Error property first in your PingCompleted event handler. Trying to use the other properties when it is not null is a guaranteed kaboom. From the PingCompletedEventArgs.Error property documentation in MSDN:

    If an exception is raised during an asynchronous operation, the class will assign the exception to the Error property. The client application’s event-handler delegate should check the Error property before accessing any properties in a class derived from AsyncCompletedEventArgs; otherwise, the property will raise a TargetInvocationException with its InnerException property holding a reference to Error.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a Windows Form that includes a combo box control, and I wanted
I'm building a windows application that search items from sharepoint document libraries, using the
I am building a Windows form application using .NET 3.5. I would like to
I'm building an app which needs display a particular form always on top (this
I'm building a simple data entry app in WPF form using the MVVM pattern.
Am building windows form application for a Hospital using VS2010 ON ACCESS 2010. I
I'm building a Windows Forms form in C# with various elements in a panel
I'm building a Windows Phone 7 app, and I need a reference to my
I am building a Windows forms application using VS2010. I want to read the
I am building a windows form in C#. Along the bottom of my form,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.