private void OnTimer(object sender, ElapsedEventArgs e)
 {
     timer.Stop();
     using (var db = new AromaVioletDataContext())
     {
         var executeAt = DateTime.Now;
         var procedures = (from item in db.SystemProcedures
                           where item.Active && item.LastRun.AddMilliseconds((double)(item.Interval * item.SystemIntervalSpecifier.MilisecondConverter)) < executeAt
                           select item).ToArray();
         foreach (var procedure in procedures)
         {
             try
             {
                 procedure.LastRun = DateTime.Now;
                 db.ExecuteCommand(procedure.ProcedureName);
             }
             catch(Exception ex)
             {
                 var msg = new SystemProcedureMessage() {Message = ex.Message, MessageDate=DateTime.Now, SystemProcedureId=procedure.SystemProcedureId,SystemProcedureMessageId=Guid.NewGuid() };
                 db.SystemProcedureMessages.InsertOnSubmit(msg);
             }
                 db.SubmitChanges();
         }
         var nextRun = (from item in db.SystemProcedures
                        where item.Active
                        select item.LastRun.AddMilliseconds((double)(item.Interval * item.SystemIntervalSpecifier.MilisecondConverter))).Max();
         var msec = nextRun.Subtract(DateTime.Now).TotalMilliseconds;
         timer.Interval = msec;
         timer.Start();
     }
 }
		private void detach_SystemProcedureMessages(SystemProcedureMessage entity)
		{
			this.SendPropertyChanging();
			entity.SystemProcedure = null;
		}
 partial void UpdateSystemProcedureMessage(SystemProcedureMessage instance);
 partial void DeleteSystemProcedureMessage(SystemProcedureMessage instance);
 partial void InsertSystemProcedureMessage(SystemProcedureMessage instance);