Changeset 1772


Ignore:
Timestamp:
2/8/2010 8:25:51 AM (2 years ago)
Author:
lowjoel
Message:

Allow all IDisposable patterns to be reentrant. Addresses #275: Code Review

Location:
branches/eraser6/CodeReview
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • branches/eraser6/CodeReview/Eraser.Manager/DirectExecutor.cs

    r1771 r1772  
    5151        protected override void Dispose(bool disposing) 
    5252        { 
     53            if (thread == null || schedulerInterrupt == null) 
     54                return; 
     55 
    5356            if (disposing) 
    5457            { 
     
    7376            } 
    7477 
     78            thread = null; 
     79            schedulerInterrupt = null; 
    7580            base.Dispose(disposing); 
    7681        } 
  • branches/eraser6/CodeReview/Eraser.Manager/ManagerLibrary.cs

    r1681 r1772  
    5757        protected virtual void Dispose(bool disposing) 
    5858        { 
     59            if (SettingsManager == null) 
     60                return; 
     61 
    5962            if (disposing) 
    6063            { 
  • branches/eraser6/CodeReview/Eraser.Manager/Plugins.cs

    r1681 r1772  
    160160        protected override void Dispose(bool disposing) 
    161161        { 
     162            if (plugins == null) 
     163                return; 
     164 
    162165            if (disposing) 
    163166            { 
     
    168171                        plugin.Plugin.Dispose(); 
    169172            } 
     173 
     174            plugins = null; 
    170175        } 
    171176 
  • branches/eraser6/CodeReview/Eraser.Manager/RemoteExecutor.cs

    r1745 r1772  
    104104        protected override void Dispose(bool disposing) 
    105105        { 
     106            if (thread == null || serverLock == null) 
     107                return; 
     108 
    106109            if (disposing) 
    107110            { 
    108111                //Close the polling thread that creates new server instances 
    109112                thread.Abort(); 
     113                thread.Join(); 
    110114 
    111115                //Close all waiting streams 
     
    121125            } 
    122126 
     127            thread = null; 
     128            serverLock = null; 
    123129            base.Dispose(disposing); 
    124130        } 
     
    315321        protected override void Dispose(bool disposing) 
    316322        { 
     323            if (client == null) 
     324                return; 
     325 
    317326            if (disposing) 
    318327            { 
     
    320329            } 
    321330 
     331            client = null; 
    322332            base.Dispose(disposing); 
    323333        } 
  • branches/eraser6/CodeReview/Eraser.Util/Security.cs

    r1770 r1772  
    148148        private void Dispose(bool disposing) 
    149149        { 
     150            //If we already have run Dispose, then handle will be null. 
     151            if (handle == null) 
     152                return; 
     153 
    150154            if (disposing) 
    151155                handle.Close(); 
     156 
     157            //Don't run Dispose again. 
     158            handle = null; 
    152159        } 
    153160 
  • branches/eraser6/CodeReview/Eraser.Util/VolumeInfo.cs

    r1770 r1772  
    747747        private void Dispose(bool disposing) 
    748748        { 
     749            if (Stream == null) 
     750                return; 
     751 
    749752            //Flush the contents of the buffer to disk since after we unlock the volume 
    750753            //we can no longer write to the volume. 
     
    758761                throw new IOException("Could not unlock volume."); 
    759762            } 
     763 
     764            //Set the stream to null so that we won't run this function again. 
     765            Stream = null; 
    760766        } 
    761767 
  • branches/eraser6/CodeReview/Eraser/Program.ConsoleProgram.cs

    r1770 r1772  
    7474            protected virtual void Dispose(bool disposing) 
    7575            { 
     76                if (ConsoleWindow == null) 
     77                    return; 
     78 
    7679                //Flush the buffered output to the console 
    7780                Console.Out.Flush(); 
     
    8790                        ConsoleWindow.Dispose(); 
    8891                } 
     92 
     93                ConsoleWindow = null; 
    8994            } 
    9095            #endregion 
  • branches/eraser6/CodeReview/Eraser/Program.GuiProgram.cs

    r1769 r1772  
    7272            protected virtual void Dispose(bool disposing) 
    7373            { 
     74                if (GlobalMutex == null) 
     75                    return; 
     76 
    7477                if (disposing) 
    7578                    GlobalMutex.Close(); 
     79                GlobalMutex = null; 
    7680            } 
    7781 
  • branches/eraser6/CodeReview/Eraser/Settings.cs

    r1770 r1772  
    4949            public RegistrySettings(Guid pluginId, RegistryKey key) 
    5050            { 
    51                 this.pluginID = pluginId; 
    52                 this.key = key; 
     51                this.PluginID = pluginId; 
     52                this.Key = key; 
    5353            } 
    5454 
     
    6868            private void Dispose(bool disposing) 
    6969            { 
     70                if (Key == null) 
     71                    return; 
     72 
    7073                if (disposing) 
    71                     key.Close(); 
     74                    Key.Close(); 
     75                Key = null; 
    7276            } 
    7377 
     
    7983                { 
    8084                    //Get the raw registry value 
    81                     object rawResult = key.GetValue(setting, null); 
     85                    object rawResult = Key.GetValue(setting, null); 
    8286 
    8387                    //Check if it is a serialised object 
     
    9296                            catch (SerializationException) 
    9397                            { 
    94                                 key.DeleteValue(setting); 
     98                                Key.DeleteValue(setting); 
    9599                                MessageBox.Show(S._("Could not load the setting {0}\\{1} for " + 
    96                                         "plugin {2}. The setting has been lost.", key, setting, 
    97                                         pluginID.ToString()), 
     100                                        "plugin {2}. The setting has been lost.", Key, setting, 
     101                                        PluginID.ToString()), 
    98102                                    S._("Eraser"), MessageBoxButtons.OK, MessageBoxIcon.Error, 
    99103                                    MessageBoxDefaultButton.Button1, 
     
    113117                    if (value == null) 
    114118                    { 
    115                         key.DeleteValue(setting); 
     119                        Key.DeleteValue(setting); 
    116120                    } 
    117121                    else 
    118122                    { 
    119123                        if (value is bool) 
    120                             key.SetValue(setting, value, RegistryValueKind.DWord); 
     124                            Key.SetValue(setting, value, RegistryValueKind.DWord); 
    121125                        else if ((value is int) || (value is uint)) 
    122                             key.SetValue(setting, value, RegistryValueKind.DWord); 
     126                            Key.SetValue(setting, value, RegistryValueKind.DWord); 
    123127                        else if ((value is long) || (value is ulong)) 
    124                             key.SetValue(setting, value, RegistryValueKind.QWord); 
     128                            Key.SetValue(setting, value, RegistryValueKind.QWord); 
    125129                        else if (value is string) 
    126                             key.SetValue(setting, value, RegistryValueKind.String); 
     130                            Key.SetValue(setting, value, RegistryValueKind.String); 
    127131                        else 
    128132                            using (MemoryStream stream = new MemoryStream()) 
    129133                            { 
    130134                                new BinaryFormatter().Serialize(stream, value); 
    131                                 key.SetValue(setting, stream.ToArray(), RegistryValueKind.Binary); 
     135                                Key.SetValue(setting, stream.ToArray(), RegistryValueKind.Binary); 
    132136                            } 
    133137                    } 
     
    138142            /// The GUID of the plugin whose settings this object is storing. 
    139143            /// </summary> 
    140             private Guid pluginID; 
     144            private Guid PluginID; 
    141145 
    142146            /// <summary> 
    143147            /// The registry key where the data is stored. 
    144148            /// </summary> 
    145             private RegistryKey key; 
     149            private RegistryKey Key; 
    146150        } 
    147151 
Note: See TracChangeset for help on using the changeset viewer.