我有一個創建一個類,操縱圖片的新實例,並將其保存到磁盤並行的foreach功能...不可靠的並行循環失敗4,滿分400倍
然而約4倍出400,圖片被保存到磁盤,但沒有被操縱,我的理論是,當它發生時,我的班級中存在的一些屬性爲空,當他們不支持...
4 (有時3個)錯誤主要發生在並行循環的前10個圖像中。
沒有錯誤信息,它只是跳過我的一些代碼,出於某種原因......當它是parralel時,我的斷點不工作,所以很難調試。
有關如何進行/調試/修復的任何建議?
代碼的要求
private static void GenerateIcons(Effects effect)
{
DirectoryInfo dir = new DirectoryInfo(HttpContext.Current.Server.MapPath(@"~\Icons\Original\"));
FileInfo[] ff = dir.GetFiles();
string mappath = HttpContext.Current.Server.MapPath(@"~\Icons\");
List<string> paths = new List<string>();
string ids = GetAllEffectIds(effect.TinyUrlCode);
Parallel.ForEach(ff, item =>
{
if (!File.Exists(mappath + @"Generated\" + ids + "-" + item.Name))
{
paths.Add(mappath + @"Generated\" + ids + "-" + item.Name);
ApplyEffects f = new ApplyEffects(effect, item.Name, mappath);
f.SaveIcon();
}
});
//Zip icons!
ZipFiles(paths, effect.TinyUrlCode, ids, effect.General.Prefix);
}
我會改變代碼的4號線應該修復它。 – ChaosPandion
@ChaosPandion,我個人會在第400行這樣做。第4行對我來說看起來是正確的:-) –
@ChaosPandion哈哈xD,但它是空的! – BjarkeCK