Merge pull request #347 from JamesB7/master
[mono.git] / mcs / class / System / System.Diagnostics / PerformanceCounter.cs
index 11ba430550c3729dedac935452ec25dac670cd18..f76f0950f459bbf951ebbf0ebba82e30b0f097bf 100644 (file)
@@ -36,16 +36,11 @@ using System.ComponentModel.Design;
 using System.Diagnostics;
 using System.Runtime.InteropServices;
 using System.Runtime.CompilerServices;
-#if NET_2_0
 using System.Runtime.ConstrainedExecution;
-#endif
 
 namespace System.Diagnostics {
 
        // must be safe for multithreaded operations
-#if !NET_2_0
-       [Designer ("Microsoft.VisualStudio.Install.PerformanceCounterDesigner, " + Consts.AssemblyMicrosoft_VisualStudio)]
-#endif
        [InstallerType (typeof (PerformanceCounterInstaller))]
        public sealed class PerformanceCounter : Component, ISupportInitialize 
        {
@@ -61,13 +56,9 @@ namespace System.Diagnostics {
                bool valid_old;
                bool changed;
                bool is_custom;
-#if NET_2_0
                private PerformanceCounterInstanceLifetime lifetime;
-#endif
 
-#if NET_2_0
                [Obsolete]
-#endif
                public static int DefaultFileMappingSize = 524288;
 
                // set catname, countname, instname to "", machname to "."
@@ -160,8 +151,10 @@ namespace System.Diagnostics {
                        if (!is_custom)
                                readOnly = true;
                        // invalid counter, need to handle out of mem
-                       if (impl == IntPtr.Zero)
-                               throw new InvalidOperationException ();
+
+                       // TODO: reenable this
+                       //if (impl == IntPtr.Zero)
+                       //      throw new InvalidOperationException ();
                        changed = false;
                }
 
@@ -212,14 +205,12 @@ namespace System.Diagnostics {
                        }
                }
 
-#if NET_2_0
                [MonoTODO]
                [DefaultValue (PerformanceCounterInstanceLifetime.Global)]
                public PerformanceCounterInstanceLifetime InstanceLifetime {
                        get { return lifetime; }
                        set { lifetime = value; }
                }
-#endif
 
                [DefaultValue (""), ReadOnly (true), RecommendedAsConfigurable (true)]
                [TypeConverter ("System.Diagnostics.Design.InstanceNameConverter, " + Consts.AssemblySystem_Design)]
@@ -321,15 +312,16 @@ namespace System.Diagnostics {
                }
 
                // may throw InvalidOperationException, Win32Exception
-#if NET_2_0
                [ReliabilityContract (Consistency.WillNotCorruptState, Cer.MayFail)]
-#endif
                public long IncrementBy (long value)
                {
                        if (changed)
                                UpdateInfo ();
-                       if (readOnly)
-                               throw new InvalidOperationException ();
+                       if (readOnly) {
+                               // FIXME: This should really throw, but by now set this workaround in place.
+                               //throw new InvalidOperationException ();
+                               return 0;
+                       }
                        return UpdateValue (impl, true, value);
                }
 
@@ -364,9 +356,7 @@ namespace System.Diagnostics {
 
                // may throw InvalidOperationException, Win32Exception
                [MonoTODO]
-#if NET_2_0
                [ReliabilityContract (Consistency.WillNotCorruptState, Cer.MayFail)]
-#endif
                public void RemoveInstance ()
                {
                        throw new NotImplementedException ();