Diff of /BtProxLock.cs [31f72c] .. [887b2f] Maximize Restore

  Switch to side-by-side view

--- a/BtProxLock.cs
+++ b/BtProxLock.cs
@@ -95,12 +95,12 @@
         /// <summary>
         /// player of ticks sound
         /// </summary>
-        private readonly SoundPlayer m_player;
+        private SoundPlayer m_player;
 
         /// <summary>
         /// is this application hidden on startup?
         /// </summary>
-        private readonly bool m_isHidden;
+        private bool m_isHidden;
 
         /// <summary>
         /// get state of application window
@@ -113,12 +113,12 @@
         /// <summary>
         /// logger used by this locker
         /// </summary>
-        private readonly Logger m_logger;
+        private Logger m_logger;
 
         /// <summary>
         /// resource manager used to pull data
         /// </summary>
-        private static readonly ResourceManager m_rmg = new ResourceManager(
+        private static readonly ResourceManager MRmg = new ResourceManager(
             "btprox.LanguageResources",
            Assembly.GetExecutingAssembly());
 
@@ -131,18 +131,8 @@
         /// <summary>
         /// default constructor
         /// </summary>
-        ///
-        /// <param name="args">
-        /// program command line arguments
-        /// </param>
-        public BtProxLock(IEnumerable<string> args)
-        {
-            /* command line parser */
-            Arguments argParser;
-
-            /* should window log be used */
-            bool uwl;
-
+        public BtProxLock()
+        {
             /* load user settings for this application */
             m_settings = new Settings();
 
@@ -151,7 +141,17 @@
                 new CultureInfo(new Settings().locale);
 
             InitializeComponent();
-
+        }
+
+        /// <summary>
+        /// initialize the object
+        /// </summary>
+        ///
+        /// <param name="args">
+        /// program command line arguments
+        /// </param>
+        public void Initialize(IEnumerable<string> args)
+        {
             InitializeLanguageControls();
 
             LoadIcons();
@@ -167,7 +167,7 @@
             if (!String.IsNullOrEmpty(m_settings.DeviceAddress))
             {
                 /* is the address parsed successfully? */
-                bool isAddrParsed = BluetoothAddress.TryParse(
+                var isAddrParsed = BluetoothAddress.TryParse(
                     m_settings.DeviceAddress, out m_deviceAddr);
                 if (isAddrParsed)
                 {
@@ -178,7 +178,7 @@
             m_isHidden = false;
 
             /* see if we are started in quiet mode */
-            argParser = new Arguments(args);
+            var argParser = new Arguments(args);
             if (!String.IsNullOrEmpty(argParser["q"]) ||
                 !String.IsNullOrEmpty(argParser["quiet"]))
             {
@@ -189,7 +189,9 @@
             }
 
             /* create new logger */
-            uwl = m_settings.useWindowsLog;
+
+            /* should window log be used */
+            var uwl = m_settings.useWindowsLog;
             m_logger = new Logger(argParser["log"], uwl);
 
             /* load ticks sound */
@@ -441,28 +443,42 @@
             }
             catch (Exception e)
             {
-                try
+                ExceptionHandler(e);
+                Environment.Exit(-1);
+            }
+        }
+
+        /// <summary>
+        /// handles exception thrown by the service thread
+        /// </summary>
+        ///
+        /// <param name="e">
+        /// excepton that should be shown
+        /// </param>
+        private void ExceptionHandler(Exception e)
+        {
+            try
+            {
+                var strMsg = String.Format(
+                    "Exception {0}: {1}{2}At{3}",
+                    e.GetType(),
+                    e.Message,
+                    Environment.NewLine,
+                    e.StackTrace);
+
+                m_logger.Event(strMsg, String.Empty);
+
+                Invoke(new MethodInvoker(() =>
                 {
-                    var strMsg = String.Format(
-                        "Exception {0}: {1}{2}At{3}",
-                        e.GetType(),
-                        e.Message,
-                        Environment.NewLine,
-                        e.StackTrace);
-
-                    m_logger.Event(strMsg, String.Empty);
-
-                    Invoke(new MethodInvoker(() =>
-                    {
-                        var ef = new ErrorMessageForm(strMsg);
-                        ef.ShowDialog();
-                    }));
-                }
-// ReSharper disable EmptyGeneralCatchClause
-                catch (Exception) { }
-// ReSharper restore EmptyGeneralCatchClause
-                Environment.Exit(-1);
-            }
+                    var ef = new ErrorMessageForm(strMsg);
+                    ef.ShowDialog();
+                }));
+            }
+            // ReSharper disable EmptyGeneralCatchClause
+            catch (Exception)
+            {
+            }
+            // ReSharper restore EmptyGeneralCatchClause
         }
 
         /// <summary>
@@ -1223,7 +1239,7 @@
         public string GetMessage(string strMsgName)
         {
             /* string from resource manager */
-            return m_rmg.GetString(strMsgName) ?? strMsgName;
+            return MRmg.GetString(strMsgName) ?? strMsgName;
         }
 
         /// <summary>