質問

I just need to know how can i use one instance of webclient indifferent pages..

code below

 WebClient webClient = new WebClient();
             webClient.DownloadStringCompleted += webClient_DownloadStringCompleted;

            webClient.DownloadStringAsync(new Uri("http://ds.co/ee.php"));
役に立ちましたか?

解決

What you want to do is create a network layer. This layer will allow you to use the same WebClient for what ever you want.

For example:

public static class NetworkLayer{
    public static WebClient wc;

    public void InitializeWebClient(){
       wc = new WebClient();       
    }
    public void MakeCall(Uri uri){
      if(!wc.isBusy){
          wc.DownloadStringCompleted += (s,a)=>
          {  
             //Get your results
          };

          wc.DownloadStringAsync(uri);
       }
    }
}

MainPage.XAML.cs would reference your network layer

NetworkLayer.Initialize();
NetworkLayer.MakeCall(new Uri("http://www.google.com",UriKind.RelativeOrAbsolute));
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top