<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.IO.Ports;
using Toggl;
using Microsoft.VisualBasic;

namespace Arduino_Toggl
{
    class Program
    {
        #region HandlerRoutine

        // Constants which sends HandlerRoutine
        public enum CtrlTypes
        {
            CTRL_C_EVENT = 0,
            CTRL_BREAK_EVENT = 1,
            CTRL_CLOSE_EVENT = 2,
            CTRL_LOGOFF_EVENT = 5,
            CTRL_SHUTDOWN_EVENT = 6
        }

        // Declare SetConsoleCtrlHandler of Win32 API
        [DllImport("Kernel32")]
        static extern bool
            SetConsoleCtrlHandler(HandlerRoutine Handler, bool Add);

        // Delegate which sends HanlerRoutine to SetConsoleCtrlHandler function
        delegate bool HandlerRoutine(CtrlTypes CtrlType);

        HandlerRoutine myHandlerOnExit;

        /// <summary>
        /// HandlerRoutine
        /// </summary>
        /// <param name="ctrlType"></param>
        /// <returns></returns>
        bool myHandler(CtrlTypes ctrlType)
        {
            // Close serial port connection
            if (statusChecker.mySerialPort.IsOpen)
            {
                statusChecker.mySerialPort.Close();
            }

            return false;
        }

        #endregion

        #region Private member variables

        StatusChecker statusChecker;

        #endregion

        #region Constructor

        /// <summary>
        /// Constructor
        /// </summary>
        Program()
        {
            // Set myHandler
            myHandlerOnExit = new HandlerRoutine(myHandler);
            SetConsoleCtrlHandler(myHandler, true);

            statusChecker = new StatusChecker();<commit_msg>Fix null reference exception when closing window refs #1<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.IO.Ports;
using Toggl;
using Microsoft.VisualBasic;

namespace Arduino_Toggl
{
    class Program
    {
        #region HandlerRoutine

        // Constants which sends HandlerRoutine
        public enum CtrlTypes
        {
            CTRL_C_EVENT = 0,
            CTRL_BREAK_EVENT = 1,
            CTRL_CLOSE_EVENT = 2,
            CTRL_LOGOFF_EVENT = 5,
            CTRL_SHUTDOWN_EVENT = 6
        }

        // Declare SetConsoleCtrlHandler of Win32 API
        [DllImport("Kernel32")]
        static extern bool
            SetConsoleCtrlHandler(HandlerRoutine Handler, bool Add);

        // Delegate which sends HandlerRoutine to SetConsoleCtrlHandler function
        private delegate bool HandlerRoutine(CtrlTypes CtrlType);

        //static HandlerRoutine myHandlerOnExit;
        static HandlerRoutine myHandlerOnExit;

        /// <summary>
        /// HandlerRoutine
        /// </summary>
        /// <param name="ctrlType"></param>
        /// <returns></returns>
        private bool myHandler(CtrlTypes ctrlType)
        {
            // Close serial port connection
            if (statusChecker.mySerialPort.IsOpen)
            {
                statusChecker.mySerialPort.Close();
            }

            return false;
        }

        #endregion

        #region Private member variables

        StatusChecker statusChecker;

        #endregion

        #region Constructor

        /// <summary>
        /// Constructor
        /// </summary>
        Program()
        {
            // Set myHandler
            myHandlerOnExit = new HandlerRoutine(myHandler);
            SetConsoleCtrlHandler(myHandlerOnExit, true);

            statusChecker = new StatusChecker();
{'fraction_non_alphanumeric': 0.07820032137118371, 'fraction_numerical': 0.005088377075522228, 'mean_word_length': 1.8664620107444359, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3853730', 'n_tokens_mistral': 1007, 'n_tokens_neox': 940, 'n_words': 231}