也许这是一个重复((但我没有找到任何在 Parallel.Foreach 中使用 binnaryformatter 的示例代码。有人可以提供它的示例吗?代码示例
Parralel.ForEach(files, fileCurr=>
{
using(lib.Accesser("fileType", fileNameSpec))
{
LoadFileData(fileNameSpec,fileCurr,cancellationToken, progressCallback);
}
});
and
LoadFileData(fileNameSpec,fileCurr,cancellationToken, progressCallback)
{
using(lib2.load(fileCurr.name))
{
foreach(var v in fileCurr.include)
{
var objectForSerialization = loadObj(v);
//my code goes below
System.IO.Stream stream = System.IO.File.Open("J:\\volume", FileMode.OpenOrCreate);
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bformatter = new BinaryFormatter();
bformatter.Serialize(stream, objectForSerialization);
stream.Close();
//but this fil will be locked by multyply writes
}
}
}