2014-04-08 6 views
0

주가 값의 문자열 표현 (Yahoo finance API를 통해)을 다운로드했습니다. 그러나 String 변수에 값을 할당하려고하면 이전 값을 유지하고 변경되지 않습니다. 여기에 코드가 있습니다.문자열 변수 값이 변경되지 않습니다

public partial class MainPage : PhoneApplicationPage 
{ 
    // Constructor 
    public MainPage() 
    { 
     InitializeComponent(); 
    } 

    String result = "Default"; 

    public void wb_DownloadStringCompleted(Object sender, DownloadStringCompletedEventArgs e) 
    { 
     result = e.Result; 

     //I changed the application title to be sure the required string was in fact downloaded 
     ApplicationTitle.Text = e.Result; 
    } 

    //When I Click a radio button, the tile is created and inialized 
    private void radioButton1_Checked(object sender, RoutedEventArgs e) 
    { 
     WebClient wb = new WebClient(); 
     wb.DownloadStringAsync(new Uri("http://finance.yahoo.com/d/quotes.csv?s=GOOG&f=a")); 
     wb.DownloadStringCompleted += wb_DownloadStringCompleted; 

     //string result = DownloadStringCompletedEventArgs.result; 
     int newCount = 0; 

     // Application Tile is always the first Tile, even if it is not pinned to Start. 
     ShellTile TileToFind = ShellTile.ActiveTiles.First(); 

     // Application should always be found 
     if (TileToFind != null) 
     { 
      // Set the properties to update for the Application Tile. 
      // Empty strings for the text values and URIs will result in the property being cleared. 
      StandardTileData NewTileData = new StandardTileData 
      { 
       Title = "Stocks", 
       BackgroundImage = new Uri("google_icon.jpg", UriKind.Relative), 
       Count = newCount, 
       BackTitle = "Google Stock", 
       BackBackgroundImage = new Uri("google_icon.jpg", UriKind.Relative), 

       //This is where the problem is. The value of result is still "Default" 
       BackContent = result.ToString() 
      }; 

      // Update the Application Tile 
      TileToFind.Update(NewTileData); 
     } 
    } 
} 

나는 라이브 타일에서 결과를 표시하려고하고 값이 "기본"대신 주식 가치 당신은 라이브 타일을 업데이트해야합니다 "548.47"

+0

check e.Result, e.result의 값은 무엇입니까 –

+0

'wb_DownloadStringCompleted'가 끝난 후에는 어떻게됩니까? 나는 페이지/무엇이 새로 고쳐지고'result'의 값이''Default "' – DGibbs

+0

@ PoomrokcThe3years로 재설정되었는지 의심 스럽습니다. e.result의 값은 548.47입니다. textBlock (이 경우 ApplicationTitle)의 값을 설정하여 확인했습니다. – Fourth

답변

0

을 보여줍니다 다운로드 후 즉, wb_DownloadStringCompleted 처리기 내에서 완료되었습니다.

public void wb_DownloadStringCompleted(Object sender, DownloadStringCompletedEventArgs e) 
{ 
    //this can probably be a local variable 
    result = e.Result; 

    //update live tile here. 
} 

현재 코드가 비동기 작업을 시작하고 바로 타일을 업데이트합니다. 작업이 아직 완료되지 않았기 때문에 result은 여전히 ​​기본값으로 설정됩니다.

+0

감사합니다. 이것은 효과가있다. – Fourth

관련 문제