2017-06-03 55 views
0

我正在使用Visual Studio 2017並嘗試爲Windows Phone編程C#UWP應用程序。當我嘗試在主機和模擬器(Mobile emulator 10.0.15063.0)之間測試漫遊應用程序數據時,數據不會同步。即使等了幾個小時。模擬器看起來像我的電子郵件和跨設備的日曆同步一樣工作。當我搜索主機上的文件,這似乎是正確創建:在仿真器C中測試漫遊應用程序數據#

C:\Users\Owner\AppData\Local\Packages\23840StartPoint.StartPointRunning_x6wjmepvaasdr\RoamingState 

我檢查了包清單和包名和版本匹配。我嘗試了幾種不同的選擇,但沒有任何作用。我錯過了什麼。

來自GitHub的應用程序數據示例是我用來教導自己寫/讀文件的模型。它也不適用於我的設置。

var applicationData = ApplicationData.Current; 

ulong storage = applicationData.RoamingStorageQuota; 

//Create file client.txt => store data => Roaming folder 
ApplicationDataContainer roamingSettings = ApplicationData.Current.RoamingSettings; 

StorageFolder roamingFolder1 = ApplicationData.Current.RoamingFolder; 
StorageFile file1 = await roamingFolder1.CreateFileAsync(Filename1, CreationCollisionOption.ReplaceExisting); 

SetUpFlag = "true"; 
String string6 = Views.Colors101.m_BackGroundColor + ";" + Views.Colors101.m_CalendarColor + ";" + Views.Colors101.m_HeaderColor; 

String toWrite = SetUpFlag + ";" + string6; 

StorageFile xfile1 = await roamingFolder1.GetFileAsync(Filename1); 

await FileIO.WriteTextAsync(xfile1, toWrite); 

ApplicationData.Current.SignalDataChanged(); 
+0

你如何共享數據,PC和UWP之間? – ArchAngel

+0

我正在通過漫遊文件夾共享一個小文本文件(約150字節)。我是新的和不確定如何添加代碼到我的評論。你能提出一種方法嗎?我試圖添加back-ticks,但沒有奏效。 – VaBRC

+0

您可以編輯您的原始問題以添加相關的代碼段和其他更新。 –

回答

0

也許嘗試我的版本,看看它是否效果更好..

const string _listofStuffFile = "allMyStuff.txt"; 
public static async Task<bool> SaveMyListData(List<string> saveData) 
    { 
     try 
     { 
      var savedStuffFile = await ApplicationData.Current.RoamingFolder.CreateFileAsync(_listofStuffFile, CreationCollisionOption.ReplaceExisting); 
      using (Stream ws = await savedStuffFile.OpenStreamForWriteAsync()) 
      { 
       var ss = new DataContractSerializer(typeof(List<string>)); 
       ss.WriteObject(ws, saveData); 
      } 
      return true; 
     } 
     catch { } 
     return false; 
    } 

public static async Task<List<string>> GetMyListData() 
    { 
     try 
     { 
      var rs = await ApplicationData.Current.RoamingFolder.OpenStreamForReadAsync(_listofStuffFile); 
      if (rs == null) 
       return new List<string>(); 
      var ss = new DataContractSerializer(typeof(List<string>)); 
      var sr = (List<string>)ss.ReadObject(rs); 
      return sr; 
     } 
     catch { } 
     return new List<string>(); 
    } 
+0

我感謝你的努力@ArchAngel。不幸的是,你的解決方案也沒有工作。我讀到,在調試模式下,應用程序不會掛起。是否有可能需要執行某些操作來強制掛起,並且是否需要執行一些特殊操作來暫停掛起文件句柄。 – VaBRC

相關問題