ConsoleWorker update console timer with how long application has been open earlier I coded a quick console worker that runs a timer every 1 second and updates the consoles timer with how long the app has been open, how can I improve this?

using Faze.Other.App;
using log4net;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Faze.Other.Util.Console
{
    class ConsoleWorker : IDisposable
    {
        /// &lt;summary&gt;
        /// Holds an instance of Timer.
        /// &lt;/summary&gt;
        private Timer consoleWorkerTimer;

        /// &lt;summary&gt;
        /// Interval of the ConsoleWorker timer.
        /// &lt;/summary&gt;
        private int consoleWorkerInterval = 1000;

        /// &lt;summary&gt;
        /// Holds an instance of ILog.
        /// &lt;/summary&gt;
        private ILog classLogger;
        /// &lt;summary&gt;
        /// Initializes a new instance of ConsoleWorker.
        /// &lt;/summary&gt;
        public ConsoleWorker()
        {
            if (StaticSettings.includeSecondsInUptimeString &amp;&amp; consoleWorkerInterval &lt; 1000)
                consoleWorkerInterval = 1000;

            classLogger = LogManager.GetLogger(typeof(ConsoleWorker));
            consoleWorkerTimer = new Timer(new TimerCallback(timerElapsed), null, TimeSpan.FromMilliseconds(consoleWorkerInterval), TimeSpan.FromMilliseconds(consoleWorkerInterval));
        }

        /// &lt;summary&gt;
        /// Starts the worker (timer) process.
        /// &lt;/summary&gt;
        public void startWorker()
        {
            // I'll leave this for now..
        }

        /// &lt;summary&gt;
        /// Handles the timers callback once elapsed.
        /// &lt;/summary&gt;
        /// &lt;param name="timerObject"&gt;ConsoleWorker timer's object.&lt;/param&gt;
        private void timerElapsed(object timerObject)
        {
            if (Faze.getServer().getServerInformation().hasStarted())
            {
                if (StaticSettings.advancedLoggingWhenDebugging &amp;&amp; Debugger.IsAttached)
                    classLogger.Info("ConsoleWorker has elapsed -&gt; " + DateTime.Now.ToLongTimeString());

                TimeSpan serverUptime = DateTime.Now - Faze.getServer().getServerInformation().getStartedTime();

                string consoleTitleString = string.Empty;

                if (StaticSettings.includeSecondsInUptimeString)
                {
                    consoleTitleString = Faze.getServer().getServerInformation().getProjectName() + " / " + serverUptime.Days + " day" + (serverUptime.Days != 1 ? "s" : "")
                    + ", " + serverUptime.Hours + " hour" + (serverUptime.Hours != 1 ? "s" : "") + ", " +
                    serverUptime.Minutes + " minute" + (serverUptime.Minutes != 1 ? "s" : "") + " and " + serverUptime.Seconds + " second" + (serverUptime.Seconds != 1 ? "s" : "");
                }
                else
                {
                    consoleTitleString = Faze.getServer().getServerInformation().getProjectName() + " / " + serverUptime.Days + " day" + (serverUptime.Days != 1 ? "s" : "")
                    + ", " + serverUptime.Hours + " hour" + (serverUptime.Hours != 1 ? "s" : "") + " and " +
                    serverUptime.Minutes + " minute" + (serverUptime.Minutes != 1 ? "s" : "");
                }

                System.Console.Title = consoleTitleString;
            }
        }

        public void Dispose()
        {
            consoleWorkerTimer.Dispose();
        }
    }
}
I think the first thing that you should do is create one more variable for Faze.getServer().getServerInformation().getProjectName() don't type that twice, and please don't make me read it twice.

I would also use String Interpolation (if you can) it makes this look a little cleaner.

You should pull out the stuff that is the same from the if/else statement and then use a single if statement if you want to add seconds onto the console title string, and then you can create the variable in one declaration minimizing the lines of code.

Here is what I have:

if (Faze.getServer().getServerInformation().hasStarted())
{
    if (StaticSettings.advancedLoggingWhenDebugging &amp;&amp; Debugger.IsAttached)
        classLogger.Info("ConsoleWorker has elapsed -&gt; " + DateTime.Now.ToLongTimeString());

    TimeSpan serverUptime = DateTime.Now - Faze.getServer().getServerInformation().getStartedTime();

    var projectName = Faze.getServer().getServerInformation().getProjectName();

    var consoleTitleString = $"{projectName} / {serverUptime.Days} " +
                         $"day{(serverUptime.Days != 1 ? "s" : "")}, {serverUptime.Hours} " +
                         $"hour{(serverUptime.Hours != 1 ? "s" : "")}, {serverUptime.Minutes} " +
                         $"minute{(serverUptime.Minutes != 1 ? "s" : "")}";

    if (StaticSettings.includeSecondsInUptimeString)
    {
        consoleTitleString += $" and {serverUptime.Seconds} second{(serverUptime.Seconds != 1 ? "s" : "")}";
    }

    System.Console.Title = consoleTitleString;
}




Another change that I might attempt would be to minimize some typing by creating an object from Faze.getServer().getServerInformation() so that I don't have to type that 3 times in my code,  it might look something like this.

var serverInfo = Faze.getServer().getServerInformation();
if (serverInfo.hasStarted())
{
    if (StaticSettings.advancedLoggingWhenDebugging &amp;&amp; Debugger.IsAttached)
        classLogger.Info("ConsoleWorker has elapsed -&gt; " + DateTime.Now.ToLongTimeString());

    TimeSpan serverUptime = DateTime.Now - serverInfo.getStartedTime();

    var projectName = serverInfo.getProjectName();

    var consoleTitleString = $"{projectName} / {serverUptime.Days} " +
                         $"day{(serverUptime.Days != 1 ? "s" : "")}, {serverUptime.Hours} " +
                         $"hour{(serverUptime.Hours != 1 ? "s" : "")}, {serverUptime.Minutes} " +
                         $"minute{(serverUptime.Minutes != 1 ? "s" : "")}";

    if (StaticSettings.includeSecondsInUptimeString)
    {
        consoleTitleString += $" and {serverUptime.Seconds} second{(serverUptime.Seconds != 1 ? "s" : "")}";
    }

    System.Console.Title = consoleTitleString;
}




I don't see anything that would change the private consoleWorkerInterval to anything other than a value of 1000 so I really don't see a need for this


if (StaticSettings.includeSecondsInUptimeString &amp;&amp; consoleWorkerInterval &lt; 1000)
            consoleWorkerInterval = 1000; 





Resharper also noted that you don't need the Redundant explicit delegate creation on this line of code


consoleWorkerTimer = new Timer(new TimerCallback(timerElapsed), null, TimeSpan.FromMilliseconds(consoleWorkerInterval), TimeSpan.FromMilliseconds(consoleWorkerInterval));



you don't need to create a new TimerCallback because you are creating this Timer and giving it a method to call when the time passes, so this line of code can be shorter as well

consoleWorkerTimer = new Timer(timerElapsed, null, TimeSpan.FromMilliseconds(consoleWorkerInterval), TimeSpan.FromMilliseconds(consoleWorkerInterval));