作者Kelunyang (可倫)
看板WindowsPhone
標題[問題] IsolatedStorageFileStream 的問題
時間Sun Jun 29 20:51:26 2014
因為是開發的問題所以刪掉了預設內容...
是這樣的,小弟這兩天遇到一個完全不解的問題
首先,小弟將App的設定檔放在xml裡,用以下程式碼讀取XML
string XML_PATH = Path.Combine(ApplicationData.Current.LocalFolder.Path,
"config.xml");
using (IsolatedStorageFileStream isf = new
IsolatedStorageFileStream(XML_PATH, FileMode.Open, isoStore))
{
ifvm.loadConfig(isf);
isf.Close();
isf.Dispose();
}
public void loadConfig(Stream str)
{
im.load(str);
}
public void load(Stream str)
{
try
{
config = XDocument.Load(str); //會錯在這裡
}
catch
{
throw new xmlException();
}
}
這樣的操作在主程式中都沒有問題,但當同樣的程式碼放到taskAgent做背景程式的時候
loadConfig裡面的 config = XDocument.Load(str); 就會發生XML讀取錯誤,代碼是
Data at the root level is invalid ,而這個錯誤的Line和Position都指在檔案結尾
我現在最不懂的是,為什麼我也都把stream給close了,
ScheduledActionService.LaunchForTest甚至安排在2分鐘後才啟動,但還是無法讀取XML
不知道有沒有前輩遇過類似的問題,可以給小弟一些建議... Orz
--
推 Non:If 薪水<28K Then 離職12/24 10:39
→ maddman:else 跳槽 12/24 11:18
→ tsming:goto 買樂透XD12/24 12:30
推 YUKIKASE:應該加入 #include"把上董事長女兒.h" 這個函式庫 :p12/24 12:41
推 smallworld:樓上有.h沒有lib也是夢一場 include大家都會阿 12/24 16:05
→ PUTOUCHANG:Error: invalid path12/24 19:11
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.225.51.184
※ 文章網址: http://www.ptt.cc/bbs/WindowsPhone/M.1404046290.A.2A9.html
※ 編輯: Kelunyang (36.225.51.184), 06/29/2014 21:15:11
推 YahooTaiwan:updateFPCC 的程式碼呢? 06/29 23:12
※ 編輯: Kelunyang (1.160.87.100), 06/30/2014 07:32:31
→ Kelunyang:已補上~ 06/30 07:32
→ fireslayer:在背景程式裡面log ApplicationData.Current.Loca.... 06/30 10:07
→ fireslayer:看看 06/30 10:07
→ Kelunyang:是有檔案的,不過我剛剛發現在xdocument.load前後加上lo 06/30 10:28
→ Kelunyang:ck就解開了@@ 06/30 10:28