public void Start() { Random random = new Random(); List<UnitRecord> list = new List<UnitRecord>(); DateTime tempTime = DateTime.Now; do { UnitRecord unit = new UnitRecord() { CurrnetTime = DateTime.Now, Speed = random.Next(80, 190), Weight = random.Next(1200, 2000) }; list.Add(unit); Thread.Sleep(1500); if (DateTime.Now.AddMinutes(-1) > tempTime) { SaveRecords(list); tempTime = DateTime.Now; list = new List<UnitRecord>(); } } while (!IsStopped); SaveRecords(list); }
public void InsertUnitRecord(UnitRecord record, unit ownerUnit) { using (var context = new Entities()) { unit_record newRecord = new unit_record() { unit = ownerUnit, currentTime = record.CurrnetTime, weight = record.Weight, speed = record.Speed }; context.unit_record.Add(newRecord); context.SaveChanges(); } }