Click here to Skip to main content
15,921,694 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public static void isConnected()
        {
                WebClient client = new WebClient();
                client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
                client.OpenReadAsync(new Uri("http://www.google.com"));
        }

static void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
         e.Result();  
        }


when bulid the solution i got below error message

`Non-invocable member 'System.Net.OpenReadCompletedEventArgs.Result' cannot be used like a method`

pls help me
Posted
Updated 2-Apr-15 3:05am
v2

 
Share this answer
 
Comments
Rnshanmugavadivel 2-Apr-15 9:04am    
Thanks you very Much..
How to check internet connection using above code.. Please explain and help me...
i am fresher..
Richard MacCutchan 2-Apr-15 9:40am    
Explain what? You just need to check the results in your event handler. Read the documentation to see what information is made available on completion of the command.
Sergey Alexandrovich Kryukov 2-Apr-15 11:37am    
Sure, a 5.
—SA
Change your code to below.

C#
public static void isConnected()
        {
                WebClient client = new WebClient();
                client.OpenReadCompleted += new OpenReadCompletedEventHandler(client_OpenReadCompleted);
                client.OpenReadAsync(new Uri("http://www.google.com"));
        }

static void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            reply = (Stream)e.Result;
            s = new StreamReader (reply);
            string strResult = s.ReadToEnd ();
        }
 
Share this answer
 
Comments
Rnshanmugavadivel 2-Apr-15 10:23am    
I use above code i got below error message in line (reply=(Stream)e.Result;

An exception occurred during the operation, making the result invalid. Check InnerException for exception details.

{System.Reflection.TargetInvocationException: An exception occurred during the operation, making the result invalid.
Check InnerException for exception details. ---> System.Security.SecurityException ---> System.Security.SecurityException: Security error.
at System.Net.Browser.BrowserHttpWebRequest.InternalEndGetResponse(IAsyncResult asyncResult)
at System.Net.Browser.BrowserHttpWebRequest.<>c__DisplayClassa.<endgetresponse>b__9(Object sendState)
at System.Net.Browser.AsyncHelper.<>c__DisplayClass4.<beginonui>b__1(Object sendState)
--- End of inner exception stack trace ---
at System.Net.Browser.AsyncHelper.BeginOnUI(SendOrPostCallback beginMethod, Object state)
at System.Net.Browser.BrowserHttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.WebClient.GetWebResponse(WebRequest request, IAsyncResult result)
at System.Net.WebClient.OpenReadAsyncCallback(IAsyncResult result)
--- End of inner exception stack trace ---
at System.ComponentModel.AsyncCompletedEventArgs.RaiseExceptionIfNecessary()
at System.Net.OpenReadCompletedEventArgs.get_Result()
at ProView.ViewModels.DashBoardViewModel.client_OpenReadCompleted(Object sender, OpenReadCompletedEventArgs e)
at System.Net.WebClient.OnOpenReadCompleted(OpenReadCompletedEventArgs e)
at System.Net.WebClient.OpenReadOperationCompleted(Object arg)}
Maheswaran_S 2-Apr-15 11:02am    
R u calling the service from any intranet connections ?

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