public static void OnTimer(Object sender)
        {
            // 12/22/2007 Paul.  In case the timer takes a long time, only allow one timer event to be processed.
            if (!bInsideTimer)
            {
                bInsideTimer = true;
                HttpApplication global = sender as HttpApplication;
                try
                {
                    // 12/30/2007 Paul.  Workflow events always get processed.
                    WorkflowUtils.Process(global.Application);

                    DbProviderFactory dbf = DbProviderFactories.GetFactory(global.Application);
                    using (DataTable dt = new DataTable())
                    {
                        using (IDbConnection con = dbf.CreateConnection())
                        {
                            con.Open();
                            string sSQL;
                            sSQL = "select *               " + ControlChars.CrLf
                                   + "  from vwSCHEDULERS_Run" + ControlChars.CrLf
                                   + " order by NEXT_RUN     " + ControlChars.CrLf;
                            using (IDbCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandText = sSQL;
                                // 01/01/2008 Paul.  The scheduler query should always be very fast.
                                // In the off chance that there is a problem, abort after 15 seconds.
                                cmd.CommandTimeout = 15;

                                using (DbDataAdapter da = dbf.CreateDataAdapter())
                                {
                                    ((IDbDataAdapter)da).SelectCommand = cmd;
                                    da.Fill(dt);
                                }
                            }
                        }
                        // 01/13/2008 Paul.  Loop outside the connection so that only one connection will be used.
                        foreach (DataRow row in dt.Rows)
                        {
                            Guid     gID        = Sql.ToGuid(row["ID"]);
                            string   sJOB       = Sql.ToString(row["JOB"]);
                            DateTime dtNEXT_RUN = Sql.ToDateTime(row["NEXT_RUN"]);
                            try
                            {
                                switch (sJOB)
                                {
                                case "function::BackupDatabase":
                                {
                                    // 01/28/2008 Paul.  Cannot perform a backup or restore operation within a transaction. BACKUP DATABASE is terminating abnormally.
                                    using (IDbConnection con = dbf.CreateConnection())
                                    {
                                        con.Open();
                                        try
                                        {
                                            string sFILENAME = String.Empty;
                                            string sTYPE     = "FULL";
                                            //SqlProcs.spSqlBackupDatabase(ref sNAME, "FULL", trn);
                                            using (IDbCommand cmd = con.CreateCommand())
                                            {
                                                cmd.CommandType = CommandType.StoredProcedure;
                                                cmd.CommandText = "spSqlBackupDatabase";
                                                IDbDataParameter parFILENAME = Sql.AddParameter(cmd, "@FILENAME", sFILENAME, 255);
                                                IDbDataParameter parTYPE     = Sql.AddParameter(cmd, "@TYPE", sTYPE, 20);
                                                parFILENAME.Direction = ParameterDirection.InputOutput;
                                                cmd.ExecuteNonQuery();
                                                sFILENAME = Sql.ToString(parFILENAME.Value);
                                            }
                                            SplendidError.SystemMessage(global.Application, "Information", new StackTrace(true).GetFrame(0), "Database backup complete " + sFILENAME);
                                        }
                                        catch (Exception ex)
                                        {
                                            SplendidError.SystemMessage(global.Application, "Error", new StackTrace(true).GetFrame(0), Utils.ExpandException(ex));
                                        }
                                    }
                                    break;
                                }

                                case "function::BackupTransactionLog":
                                {
                                    // 01/28/2008 Paul.  Cannot perform a backup or restore operation within a transaction. BACKUP DATABASE is terminating abnormally.
                                    using (IDbConnection con = dbf.CreateConnection())
                                    {
                                        con.Open();
                                        try
                                        {
                                            string sFILENAME = String.Empty;
                                            string sTYPE     = "LOG";
                                            //SqlProcs.spSqlBackupDatabase(ref sNAME, "LOG", trn);
                                            using (IDbCommand cmd = con.CreateCommand())
                                            {
                                                cmd.CommandType = CommandType.StoredProcedure;
                                                cmd.CommandText = "spSqlBackupDatabase";
                                                IDbDataParameter parFILENAME = Sql.AddParameter(cmd, "@FILENAME", sFILENAME, 255);
                                                IDbDataParameter parTYPE     = Sql.AddParameter(cmd, "@TYPE", sTYPE, 20);
                                                parFILENAME.Direction = ParameterDirection.InputOutput;
                                                cmd.ExecuteNonQuery();
                                                sFILENAME = Sql.ToString(parFILENAME.Value);
                                            }
                                            SplendidError.SystemMessage(global.Application, "Information", new StackTrace(true).GetFrame(0), "Transaction Log backup complete " + sFILENAME);
                                        }
                                        catch (Exception ex)
                                        {
                                            SplendidError.SystemMessage(global.Application, "Error", new StackTrace(true).GetFrame(0), Utils.ExpandException(ex));
                                        }
                                    }
                                    break;
                                }

                                case "function::runMassEmailCampaign":
                                {
                                    // 12/30/2007 Paul.  Update the last run date before running so that the date marks the start of the run.
                                    EmailUtils.SendQueued(global.Application, Guid.Empty, Guid.Empty, false);
                                    break;
                                }

                                case "function::pruneDatabase":
                                {
                                    using (IDbConnection con = dbf.CreateConnection())
                                    {
                                        con.Open();
                                        using (IDbTransaction trn = con.BeginTransaction())
                                        {
                                            try
                                            {
                                                SqlProcs.spSqlPruneDatabase(trn);
                                                trn.Commit();
                                            }
                                            catch (Exception ex)
                                            {
                                                trn.Rollback();
                                                SplendidError.SystemMessage(global.Application, "Error", new StackTrace(true).GetFrame(0), Utils.ExpandException(ex));
                                            }
                                        }
                                    }
                                    break;
                                }

                                case "function::pollMonitoredInboxes":
                                {
                                    EmailUtils.CheckMonitored(global.Application, Guid.Empty);
                                    break;
                                }

                                case "function::pollMonitoredInboxesForBouncedCampaignEmails":
                                {
                                    EmailUtils.CheckBounced(global.Application, Guid.Empty);
                                    break;
                                }

                                case "function::CheckVersion":
                                {
                                    DataTable dtVersions = Utils.CheckVersion(global.Application);

                                    DataView vwVersions = dtVersions.DefaultView;
                                    vwVersions.RowFilter = "New = '1'";
                                    if (vwVersions.Count > 0)
                                    {
                                        global.Application["available_version"]             = Sql.ToString(vwVersions[0]["Build"]);
                                        global.Application["available_version_description"] = Sql.ToString(vwVersions[0]["Description"]);
                                    }
                                    break;
                                }
                                }
                            }
                            finally
                            {
                                using (IDbConnection con = dbf.CreateConnection())
                                {
                                    con.Open();
                                    using (IDbTransaction trn = con.BeginTransaction())
                                    {
                                        try
                                        {
                                            // 01/12/2008 Paul.  Make sure the Last Run value is updated after the operation.
                                            SqlProcs.spSCHEDULERS_UpdateLastRun(gID, dtNEXT_RUN, trn);
                                            trn.Commit();
                                        }
                                        catch (Exception ex)
                                        {
                                            trn.Rollback();
                                            SplendidError.SystemMessage(global.Application, "Error", new StackTrace(true).GetFrame(0), Utils.ExpandException(ex));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    SplendidError.SystemMessage(global.Application, "Error", new StackTrace(true).GetFrame(0), Utils.ExpandException(ex));
                }
                finally
                {
                    bInsideTimer = false;
                }
            }
        }