2012-03-22 26 views
0

想建立一個窗口電話7.1應用程序,其中在我從數據庫到我的xaml.cs文件通過Web服務得到一個用戶名。現在,我需要將該用戶名訪問到scheduledtaskagent(backgroundprocess)。即使我使用PhoneApplicationService.Current.State [「username」]來存儲我的變量值,我也無法實現它。 以下是我xaml.cs文件代碼:無法訪問從xaml.cs價值scheduletaskagent.cs中的Windows Phone 7.1應用

private void tservice_InsertUserCompleted(object sender, UTservice.InsertUserCompletedEventArgs e) 
    { 
     if (e.Result != string.Empty) 
     { 

      username = e.Result.ToString(); 
      PhoneApplicationService.Current.State["uname"] = username; 
      StartPeriodicAgent(); 

     } 

    } 

下面是scheduledtaskagent.cs

protected override void OnInvoke(ScheduledTask task) 
    { 
     string uname; 
     uname = PhoneApplicationService.Current.State["uname"].ToString(); 
    } 

的代碼時,出現了「NullReference」例外上述聲明。

有人請讓我知道解決我的問題的出路嗎?提前致謝。

回答

0

PhoneApplicationService.Current.State是進程本地的; AFAIK,你不能直接將值傳遞給後臺代理!

但是,您可以一些信息保存到一個文件中IsolatedStorage,當代理運行時讀取文件內容,並以某種方式使用它!

相關問題