Perhaps this is a duplication(( But I have not found any sample code of the using of binnaryformatter in Parallel.Foreach. Could anyone provide a sample of it? Sample of code
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
}
}
}