示例#1
0
        private async void ButtonOpenFile_Click(object sender, RoutedEventArgs e)
        {
            this.StatusText.Text             = "Waiting".GetResource();
            this.ProgressBar.IsIndeterminate = true;
            var ofd = new OpenFileDialog
            {
                Filter = "CSF Document|*.csf",
            };

            if (ofd.ShowDialog() != true)
            {
                this.StatusText.Text             = "Cancel".GetResource();
                this.ProgressBar.IsIndeterminate = false;
                return;
            }

            GC.TryStartNoGCRegion(150 * 1024 * 1024);
            this.DocumentView.DataContext =
                await FileManager.OpenFile(ofd.FileName, this.StatusChange, this.ProgressBarChange);

            this.ProgressBar.IsIndeterminate = true;
            this.StatusText.Text             = "Sorting".GetResource();
            await Task.Run(this.DocumentView.SortListView);

            try
            {
                GC.EndNoGCRegion();
            }
            catch { }
            this.ProgressBar.IsIndeterminate = false;
            this.ProgressBar.Value           = 0;
            this.StatusText.Text             = "Complete".GetResource();
        }
示例#2
0
        private async void ButtonSaveTo_Click(object sender, RoutedEventArgs e)
        {
            var docvm = this.GetCsfDocumentViewModel();

            this.StatusText.Text             = "Waiting".GetResource();
            this.ProgressBar.IsIndeterminate = true;
            var ofd = new SaveFileDialog
            {
                Filter   = "CSF Document|*.csf",
                FileName = "ra2md.csf"
            };

            if (ofd.ShowDialog() != true)
            {
                this.StatusText.Text             = "Cancel".GetResource();
                this.ProgressBar.IsIndeterminate = false;
                return;
            }

            GC.TryStartNoGCRegion(150 * 1024 * 1024);
            await FileManager.SaveFile(ofd.FileName, docvm, this.StatusChange, this.ProgressBarChange);

            try
            {
                GC.EndNoGCRegion();
            }
            catch { }
        }
示例#3
0
        public void TestRemovedWeakReferencesAreNotContained()
        {
            var obj     = new object();
            var weakRef = new WeakReference <object>(obj);
            var list    = new WeakList <object> {
                weakRef
            };

            GC.TryStartNoGCRegion(10 * 1000000); // 10MB (should be enough)

            try
            {
                list.Remove(weakRef);
                Assert.That(list, Does.Not.Contain(weakRef));
            }
            finally
            {
                try
                {
                    GC.EndNoGCRegion();
                }
                catch
                {
                }
            }
        }
示例#4
0
		static public void CefShutdown()
		{
#if !FXBELOW46
			bool tsngc = GC.TryStartNoGCRegion(8 * 1024 * 1024);  //there's something wrong , so stop GC while shutdown the CEF
			if (!tsngc)
				WriteDebugLine("Warning , TryStartNoGCRegion failed.");
#endif
			_CefShutdownCalled = true;
			try
			{
				WriteDebugLine("cef shutdown .. " + ApplicationElapsed);
				LibCefInterop.cef_shutdown();
				WriteDebugLine("cef shutdown OK " + ApplicationElapsed);
			}
			catch (AccessViolationException x)// not able to catch ..
			{
				WriteDebugLine(x.ToString());
			}
			finally
			{
				_CefShutdownCalled = false;

#if !FXBELOW46
				if (tsngc) GC.EndNoGCRegion();
#endif
			}

#if DEBUG
#if !FXBELOW46
			GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, false);
#endif
#endif


		}
 public void IterationCleanup()
 {
     if (GCSettings.LatencyMode == GCLatencyMode.NoGCRegion)
     {
         GC.EndNoGCRegion();
     }
 }
示例#6
0
    public static int Main()
    {
        if (RuntimeInformation.ProcessArchitecture == Architecture.X86)
        {
            s_LOH_GEN = 2;
        }

        Console.WriteLine("DoubleArrayToLargeObjectHeap is {0}", Environment.GetEnvironmentVariable("complus_DoubleArrayToLargeObjectHeap"));

        try
        {
            GC.TryStartNoGCRegion(500_000);
            double[] arr = new double[101];
            if (GC.GetGeneration(arr) != s_LOH_GEN)
            {
                Console.WriteLine("Generation {0}", GC.GetGeneration(arr));
                Console.WriteLine("FAILED");
                return(1);
            }

            Console.WriteLine("PASSED");
            return(100);
        }
        finally
        {
            GC.EndNoGCRegion();
        }
    }
示例#7
0
        static void Main(string[] args)
        {
            const int N = 1000000;

            Console.WriteLine("Testing with {0} operations:", N);


            Thread.Sleep(5000);
            Console.WriteLine(GC.TryStartNoGCRegion(4000000));
            Console.WriteLine("   Optimized bitfield took {0} ms.", TestOptimized(N));
            GC.Collect(2, GCCollectionMode.Forced);
            GC.Collect(1);
            Console.WriteLine("   A byte bitfield took {0} ms.", TestBitField(N));
            GC.Collect(2, GCCollectionMode.Forced);
            GC.Collect(1);
            Console.WriteLine("   Bit getting took {0} ms.", TestGetBit(N));
            GC.Collect(2, GCCollectionMode.Forced);
            GC.Collect(1);
            Console.WriteLine("   Bit setting took {0} ms.", TestSetBit(N));
            GC.Collect(2, GCCollectionMode.Forced);
            GC.Collect(1);
            Console.WriteLine("   BitArray took {0} ms.", TestBitArray(N));
            GC.Collect(2, GCCollectionMode.Forced);
            GC.Collect(1);
            Console.WriteLine("   Bool array initialization took {0} ms.", TestBoolArrayInitialization(N));
            GC.Collect(2, GCCollectionMode.Forced);
            GC.Collect(1);
            Console.WriteLine("   Bool array reading took {0} ms.", TestBoolArrayReading(N));
            GC.Collect(2, GCCollectionMode.Forced);
            GC.Collect(1);
            GC.EndNoGCRegion();

            Console.ReadLine();
        }
        public static void TryStartNoGCRegionNegTest()
        {
            RemoteInvokeOptions options = new RemoteInvokeOptions();

            options.TimeOut = TimeoutMilliseconds;
            RemoteInvoke(() =>
            {
                Assert.Throws <InvalidOperationException>(() => GC.EndNoGCRegion());

                Assert.True(GC.TryStartNoGCRegion(1024));
                Assert.Throws <InvalidOperationException>(() => GC.TryStartNoGCRegion(1024));

                Assert.True(GC.TryStartNoGCRegion(1024, true));
                Assert.Throws <InvalidOperationException>(() => GC.TryStartNoGCRegion(1024, true));

                Assert.True(GC.TryStartNoGCRegion(1024, 1024));
                Assert.Throws <InvalidOperationException>(() => GC.TryStartNoGCRegion(1024, 1024));

                Assert.True(GC.TryStartNoGCRegion(1024, 1024, true));
                Assert.Throws <InvalidOperationException>(() => GC.TryStartNoGCRegion(1024, 1024, true));
                Assert.True(GC.TryStartNoGCRegion(1024, true));
                Assert.Equal(GCSettings.LatencyMode, GCLatencyMode.NoGCRegion);
                Assert.Throws <InvalidOperationException>(() => GCSettings.LatencyMode = GCLatencyMode.LowLatency);

                GC.EndNoGCRegion();

                return(SuccessExitCode);
            }, options).Dispose();
        }
示例#9
0
        private static void Main(string[] args)
        {
            //GCSettings.LatencyMode = GCLatencyMode.LowLatency;

            try
            {
                GC.TryStartNoGCRegion(15 * 1024 * 10124, disallowFullBlockingGC: true);        // GC.Collect-et is tartalmaz
                for (int i = 0; i < 15; i++)
                {
                    new Resource();
                }

                System.Console.WriteLine("Objects created");
            }
            finally
            {
                Console.WriteLine("No GC region end");
                if (GCSettings.LatencyMode == GCLatencyMode.NoGCRegion)
                {
                    GC.EndNoGCRegion();
                }
            }

            Console.ReadKey();
        }
示例#10
0
        private static void TestSuite <TPathfinder, TNode>(string testName)
            where TPathfinder : Pathfinder <TNode> where TNode : class, INode <TNode>, new()
        {
            const int gridSize    = 100;
            const int blockChance = 30;
            const int seed        = 1337;

            {
                var pathFinder =
                    Activator.CreateInstance(typeof(TPathfinder), gridSize, gridSize, blockChance, seed) as TPathfinder;

                GC.Collect();

                if (GC.TryStartNoGCRegion(1024 * 1024 * 128))
                {
                    var start  = pathFinder.GetNodeAt(0, 0);
                    var finish = pathFinder.GetNodeAt(pathFinder.Width - 1, pathFinder.Height - 1);

                    var stopwatch = new Stopwatch();
                    stopwatch.Start();
                    var path = pathFinder.AStar(start, finish);
                    var res  = stopwatch.ElapsedMilliseconds;

                    Console.WriteLine($"{testName} l: {path.Count()} t: {res} ms");

                    GC.EndNoGCRegion();
                }
                else
                {
                    throw new InsufficientMemoryException();
                }
            }

            GC.Collect();
        }
示例#11
0
    public static int Main()
    {
        if (Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE") == "x86")
        {
            s_LOH_GEN = 2;
        }

        Console.WriteLine("DoubleArrayToLargeObjectHeap is {0}", Environment.GetEnvironmentVariable("complus_DoubleArrayToLargeObjectHeap"));

        try
        {
            GC.TryStartNoGCRegion(500_000);
            double[] arr = new double[101];
            if (GC.GetGeneration(arr) != s_LOH_GEN)
            {
                Console.WriteLine("Generation {0}", GC.GetGeneration(arr));
                Console.WriteLine("FAILED");
                return(1);
            }

            Console.WriteLine("PASSED");
            return(100);
        }
        finally
        {
            GC.EndNoGCRegion();
        }
    }
示例#12
0
        static void Main(string[] args)
        {
            const int amount = 500000;

            using (new SimpleGCEventListener())
            {
                Console.ReadLine();
                Console.WriteLine("Started!" + Environment.NewLine);

                GC.TryStartNoGCRegion(8 * amount + 50 * amount);

                var tonsOfObjects = new object[amount];
                for (var i = 0; i < amount; i++)
                {
                    tonsOfObjects[i] = new byte[8];
                    if (i % 10000 == 0)
                    {
                        tonsOfObjects[i] = new byte[85000]; // candidate for LOH
                    }
                }

                GC.EndNoGCRegion();

                Console.WriteLine("Finished!");
                Console.ReadLine();
            }
        }
示例#13
0
        public int Run()
        {
            long mbs = long.Parse(Console.ReadLine());

            //bool success = GC.TryStartNoGCRegion(3916L * 1024 * 1024);
            //Console.WriteLine(success);
            while (true)
            {
                try
                {
                    if (GC.TryStartNoGCRegion(mbs * 1024 * 1024, 0, false))
                    {
                        break;
                    }
                }
                catch (ArgumentOutOfRangeException)
                {
                    mbs -= 1;
                }
            }
            Console.Write(mbs);
            GC.EndNoGCRegion();
            Console.ReadLine();
            return(0);
        }
示例#14
0
 ///////////////////////////////////////////////////////////////////////
 // Listing 11-7
 public void ExampleNoGCRegionCreation()
 {
     // in case of previous finally block not executed
     if (GCSettings.LatencyMode == GCLatencyMode.NoGCRegion)
     {
         GC.EndNoGCRegion();
     }
     if (GC.TryStartNoGCRegion(1024, true))
     {
         try
         {
             // Do some work.
         }
         finally
         {
             try
             {
                 GC.EndNoGCRegion();
             }
             catch (InvalidOperationException ex)
             {
                 // Log message
             }
         }
     }
 }
示例#15
0
        static void Main(string[] args)
        {
            try
            {
                GCSettings.LatencyMode = GCLatencyMode.Batch;
                GC.TryStartNoGCRegion(150 * 1024 * 1024, false);

                Console.WriteLine("== Memory consumption ==");
                Console.WriteLine();

                for (var i = 1; i <= 90_000; i++)
                {
                    var x = LazyProxyGenerator.CreateLazyProxyFor <IService>(() => new Service());

                    x.Incrementa(); // instance is created here!

                    if (i % 2000 == 0)
                    {
                        Console.WriteLine($"{ i.ToString("0.0,0").PadLeft(10) } >> { (GC.GetTotalMemory(false) / 1024).ToString("0.0,0") } Kb");
                    }
                }
            }
            finally
            {
                Console.ReadLine();

                GC.EndNoGCRegion();
            }
        }
示例#16
0
        public static void GetGeneration_WeakReference()
        {
            RemoteInvokeOptions options = new RemoteInvokeOptions();

            options.TimeOut = TimeoutMilliseconds;
            RemoteExecutor.Invoke(() =>
            {
                Func <WeakReference> getweakref = delegate()
                {
                    Version myobj = new Version();
                    var wkref     = new WeakReference(myobj);

                    Assert.True(GC.TryStartNoGCRegion(NoGCRequestedBudget));
                    Assert.True(GC.GetGeneration(wkref) >= 0);
                    Assert.Equal(GC.GetGeneration(wkref), GC.GetGeneration(myobj));
                    GC.EndNoGCRegion();

                    myobj = null;
                    return(wkref);
                };

                WeakReference weakref = getweakref();
                Assert.True(weakref != null);
#if !DEBUG
                GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true, true);
                Assert.Throws <ArgumentNullException>(() => GC.GetGeneration(weakref));
#endif
            }, options).Dispose();
        }
示例#17
0
文件: Garbage.cs 项目: obender12/hl18
 public static void ExitNoGC()
 {
     if (noGcCounter > 0 && Interlocked.Decrement(ref noGcCounter) <= 0 && GCSettings.LatencyMode == GCLatencyMode.NoGCRegion)
     {
         GC.EndNoGCRegion();
         GC.Collect(0);
     }
 }
示例#18
0
 public static void Main(String[] args)
 {
     if (GC.TryStartNoGCRegion(1 * 1024 * 1024))
     {
         PiDigits m = new PiDigits(Int32.Parse(args[0]));
         m.Run();
         GC.EndNoGCRegion();
     }
 }
示例#19
0
 public static void Main()
 {
     // <Snippet1>
     if (GCSettings.LatencyMode == GCLatencyMode.NoGCRegion)
     {
         GC.EndNoGCRegion();
     }
     // </Snippet1>
 }
示例#20
0
        /// <inheritdoc/>
        protected override void OnDisposeManagedResources()
        {
            base.OnDisposeManagedResources();

            if (this.isInNoGCScope)
            {
                GC.EndNoGCRegion();
            }
        }
示例#21
0
        public static void TryStartNoGCRegion_EndNoGCRegion_ThrowsInvalidOperationException()
        {
            RemoteInvokeOptions options = new RemoteInvokeOptions();

            options.TimeOut = TimeoutMilliseconds;
            RemoteExecutor.Invoke(() =>
            {
                Assert.Throws <InvalidOperationException>(() => GC.EndNoGCRegion());
            }, options).Dispose();
        }
示例#22
0
        /**
         * As puzzling as this might be, I provisionally believe it to be correct. Apparently, even if the GC is not in a NoGC region, you still need to call
         * `EndNoGCRegion` if you have called `TryStartNoGCRegion` earlier, otherwise your next call to `TryStartNoGCRegion` will fail.
         * `EndNoGCRegion` will throw an exception, but that's OK. Your next call to `TryStartNoGCRegion` will now succeed.
         *
         * Now read the above repeatedly until you got. Or just trust that it works somehow.
         **/
        public static void EndNoGCRegion()
        {
            _evListener.Stop();

            try
            {
                GC.EndNoGCRegion();
            } catch (InvalidOperationException)
            {
            }
        }
示例#23
0
 public static void Run(Action f)
 {
     try
     {
         GC.TryStartNoGCRegion(500_000);
         f();
     }
     finally
     {
         GC.EndNoGCRegion();
     }
 }
示例#24
0
 private static void RegionOnDisposed(object sender, EventArgs e)
 {
     lock (Sync)
     {
         var region = (NoGcRegion)sender;
         region.Disposed -= RegionOnDisposed;
         if (GCSettings.LatencyMode == GCLatencyMode.NoGCRegion)
         {
             GC.EndNoGCRegion();
         }
     }
 }
示例#25
0
        public static void TryStartNoGCRegion_SOHSize_LOHSize_BlockingCollection()
        {
            RemoteInvokeOptions options = new RemoteInvokeOptions();

            options.TimeOut = TimeoutMilliseconds;
            RemoteExecutor.Invoke(() =>
            {
                Assert.True(GC.TryStartNoGCRegion(NoGCRequestedBudget, NoGCRequestedBudget, true));
                Assert.Equal(GCLatencyMode.NoGCRegion, GCSettings.LatencyMode);
                GC.EndNoGCRegion();
            }, options).Dispose();
        }
示例#26
0
        public static void TryStartNoGCRegion_StartWhileInNoGCRegion_BlockingCollectionAndLOH()
        {
            RemoteInvokeOptions options = new RemoteInvokeOptions();

            options.TimeOut = TimeoutMilliseconds;
            RemoteExecutor.Invoke(() =>
            {
                Assert.True(GC.TryStartNoGCRegion(NoGCRequestedBudget, NoGCRequestedBudget, true));
                Assert.Throws <InvalidOperationException>(() => GC.TryStartNoGCRegion(NoGCRequestedBudget, NoGCRequestedBudget, true));

                Assert.Throws <InvalidOperationException>(() => GC.EndNoGCRegion());
            }, options).Dispose();
        }
示例#27
0
        protected virtual void Dispose(bool disposing)
        {
            if (isDisposed)
            {
                return;
            }

            if (disposing)
            {
                GC.EndNoGCRegion();
            }

            isDisposed = true;
        }
示例#28
0
        static void Main(string[] args)
        {
            GC.TryStartNoGCRegion(1000000);
            for (int i = 0; i < 8; ++i)
            {
                TestPrefix();
                Thread.Sleep(500);
                TestPostfix();
                Thread.Sleep(500);
            }
            GC.EndNoGCRegion();

            Console.ReadLine();
        }
示例#29
0
        public void Allocation_free()
        {
            var totalMemory = GC.GetTotalMemory(true);

            AssertTrue(GC.TryStartNoGCRegion(1000));

            String_as_read_only_span();
            Substring_as_read_only_slice();
            Array_as_mutable_span_and_slice();

            // Crude, not a guarantee that nothing was allocated
            GC.EndNoGCRegion();
            Assert.Equal(0, GC.GetTotalMemory(false) - totalMemory);
        }
示例#30
0
        public static void TryStartNoGCRegion_SOHSize_LOHSize()
        {
            RemoteInvokeOptions options = new RemoteInvokeOptions();

            options.TimeOut = TimeoutMilliseconds;
            RemoteInvoke(() =>
            {
                Assert.True(GC.TryStartNoGCRegion(NoGCRequestedBudget, NoGCRequestedBudget));
                Assert.Equal(GCSettings.LatencyMode, GCLatencyMode.NoGCRegion);
                GC.EndNoGCRegion();

                return(SuccessExitCode);
            }, options).Dispose();
        }