-1

I am using quartz.net to close the machine in supermarket,when at 22:00.Trigger the shutdown event:

        public void Execute(IJobExecutionContext context)
        {               
            logger.Info("shutdown.....");
            try
            {
                StatusHelper.ShutdownComputerImpl(MachineOperType.Shutdown);
            }
            catch (Exception e)
            {
                logger.Error("Shutdown computer encount an error", e);
            }
        }

But the quartz.net will trigger the job when first time run!!!!

So I could get the system already run how much time, if less than 10 minutes, the function could not be execute.Like this:

public void Execute(IJobExecutionContext context)
            {               
                logger.Info("shutdown.....");
                try
                {
                     if(GetCurrentProcessRuntime()>50)
                     {
                         StatusHelper.ShutdownComputerImpl(MachineOperType.Shutdown);
                     }
                }
                catch (Exception e)
                {
                    logger.Error("Shutdown computer encount an error", e);
                }
            }

I am programming in C# Winform,visual studio 2013,and i want to get the program run time from start,how to get it?May be the program run 2 hours,and the time will more than 2 hour(or minutes).

I am not measure the code run how much time,I want to get system run time from start!!!

Sébastien Sevrin
  • 5,267
  • 2
  • 22
  • 39
Dolphin
  • 29,069
  • 61
  • 260
  • 539

1 Answers1

0

You can try using stopwatch class:

using System.Diagnostics.Stopwatch
class Program
{
    static void Main()
    {
    // Create new stopwatch
    Stopwatch stopwatch = new Stopwatch();

    // Begin timing
    stopwatch.Start();

    // Do something     

    // Stop timing
    stopwatch.Stop();

    // Write result
    Console.WriteLine("Time elapsed: {0}",
        stopwatch.Elapsed);
    }
}
israel altar
  • 1,768
  • 1
  • 16
  • 24