Compare Page Revisions
« Older Revision - Back to Page History - Newer Revision »
[Timestamp] public byte[] RowVersion { get; set; }
var done = false; var iterNum = 1; var maxIterations = 5; do { try { LoggingEngine.Info($"Starting Iteration {iterNum}."); /* TODO: Implement logic to update record. */ db.SaveChanges(); done = true; } catch (SqlException ex) when (ex.Number == 1205) // 1205 = deadlock victim { iterNum++; done = (iterNum >= maxIterations); if (done) { LoggingEngine.Exception($"Deadlock exception while trying to " + $"do stuff - iteration {iterNum}. EXITING!", ex); } else { LoggingEngine.Exception($"Deadlock exception while trying to " + $"do stuff - iteration {iterNum}. Retrying operation.", ex); } } catch (DbUpdateConcurrencyException ex) { iterNum++; done = (iterNum > maxIterations); if (done) { LoggingEngine.Exception($"Concurrency exception while trying to " + $"do stuff - iteration {iterNum-1}. EXITING!", ex); } else { LoggingEngine.Exception($"Concurrency exception while trying to " + $"do stuff - iteration {iterNum-1}. Retrying.", ex); foreach (var en in ex.Entries) { en.Reload(); // RELOAD = database wins } } } catch (Exception ex) { done = true; LoggingEngine.Exception($"Exception while trying to do stuff", ex); } } while (!done);
private long ByteArrayToLong(byte[] input) { if (input.Length > 8) { throw new InvalidOperationException("Byte array can have no more than 8 elements."); } var result = BitConverter.ToInt64(input.Reverse().ToArray(), 0); return result; } private byte[] LongToByteArray(long input) { var result = BitConverter.GetBytes(input).Reverse().ToArray(); return result; }
ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.