This is a example of the exception:
System.InvalidOperationException: 'A second operation started on this context before a previous operation completed. Any instance members are not guaranteed to be thread safe.'
This is a example of the code:
private Data.Interfaces.IUnitOfWork _unitOfWork;
public SynchronizePatch(Data.Interfaces.IUnitOfWork iUnitOfWork) {
this._unitOfWork = iUnitOfWork;
}
public void Run() {
var tActionBlock = new ActionBlock<Data.Models.Base.Device>(
_ => this.RunDevice(_),
new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = 10 }
);
var tDevices = this._unitOfWork.Get<Data.Models.Base.Device>().Queryable().ToList();
tDevices.ForEach(q => tActionBlock.Post(q));
tActionBlock.Complete();
tActionBlock.Completion.Wait();
}
public void RunDevice(Data.Models.Base.Device iDevice) {
var tPatches = this._unitOfWork.Get<Data.Models.Base.DevicePatch>().Queryable().Where(q => q.Device.Guid == iDevice.Guid).ToList();
tPatches.ForEach(q => q.MaxFocusLastSync = DateTime.Now);
this._unitOfWork.Save();
}