Animatroller.MonoExpander.Main.Execute C# (CSharp) Method

Execute() public method

public Execute ( CancellationToken cancel ) : void
cancel System.Threading.CancellationToken
return void
        public void Execute(CancellationToken cancel)
        {
            try
            {
                this.log.Info("Starting up listeners, etc");

                this.log.Info("Running");

                if (this.autoStartBackgroundTrack)
                    PlayNextBackground();

                var watch = Stopwatch.StartNew();
                int reportCounter = 0;
                while (!cancel.IsCancellationRequested)
                {
                    if (this.piFace != null)
                        this.piFace.PollInputPins();

                    if (this.fmodSystem != null)
                        this.fmodSystem.Update();

                    this.disposeList.ForEach(x => x.Dispose());
                    this.disposeList.Clear();

                    reportCounter++;

                    if (reportCounter % 5 == 0)
                    {
                        if (ReportChannelPosition(this.currentTrkChannel, this.currentTrack, AudioTypes.Track, ref this.lastPosTrk))
                            watch.Restart();
                    }

                    if (reportCounter % 10 == 0)
                    {
                        if (ReportChannelPosition(this.currentBgChannel, this.currentBgTrackName, AudioTypes.Background, ref this.lastPosBg))
                            watch.Restart();
                    }

                    if (reportCounter % 10 == 0 && watch.ElapsedMilliseconds > 5000)
                    {
                        // Send ping
                        this.log.Trace("Send ping");

                        SendMessage(new Ping());

                        watch.Restart();
                    }

                    Thread.Sleep(50);
                }

                this.log.Info("Shutting down");
            }
            finally
            {
                Console.CursorVisible = true;
            }
        }
    }

Usage Example

示例#1
0
        public static void Main(string[] args)
        {
            var logConfig = new LoggerConfiguration()
                            .Enrich.FromLogContext()
                            .MinimumLevel.Verbose()
                            .WriteTo.ColoredConsole(outputTemplate: TraceTemplate)
                            .WriteTo.Trace(outputTemplate: TraceTemplate)
                            .WriteTo.RollingFile(
                pathFormat: Path.Combine(AppContext.BaseDirectory, "Logs", "log-{Date}.txt"),
                outputTemplate: FileTemplate);

            log = Log.Logger = logConfig.CreateLogger();

            log.Information("Starting up!");

            try
            {
                var arguments = Args.Parse <Arguments>(args);

                var cts = new CancellationTokenSource();

                Console.CancelKeyPress += (s, e) =>
                {
                    e.Cancel = true;
                    cts.Cancel();
                };

                try
                {
                    using (var main = new Main(arguments))
                    {
                        main.Execute(cts.Token);
                    }
                }
                finally
                {
                    Console.CursorVisible = true;
                }
            }
            catch (ArgException ex)
            {
                log.Warning(ex.Message);
                Console.WriteLine(ArgUsage.GenerateUsageFromTemplate <Arguments>());
            }
            catch (Exception ex)
            {
                log.Error(ex, "Unhandled exception");
                Console.WriteLine("Unhandled exception: {0}", ex);
            }

            log.Information("Closing");
        }
All Usage Examples Of Animatroller.MonoExpander.Main::Execute