forked from PLCnext/CSharpExamples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GarbageCollection.cs
62 lines (57 loc) · 1.76 KB
/
GarbageCollection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#region Copyright
//
// Copyright (c) Phoenix Contact GmbH & Co. KG. All rights reserved.
// Licensed under the MIT. See LICENSE file in the project root for full license information.
//
#endregion
using System;
using System.Iec61131Lib;
using Eclr;
using Iec61131.Engineering.Prototypes.Types;
using Iec61131.Engineering.Prototypes.Variables;
using Iec61131.Engineering.Prototypes.Methods;
using Iec61131.Engineering.Prototypes.Common;
namespace ExampleLib
{
[FunctionBlock]
public class SET_GC_EXECUTION
{
[Input]
public bool EXECUTE;
[Input]
public bool IMPLICITE;
[Output]
public bool IS_IMPLICITE;
private bool ExecutePreviousState; // used for rising edge detection
[Initialization]
public void __Init()
{
}
[Execution]
public void __Process()
{
if (EXECUTE && !ExecutePreviousState)
{
if (IMPLICITE)
{
// Set GC to implicit collection
if (!Eclr.Environment.IsGcImplicit())
{
// Set collecting with a threshold of 100000 which means that after allocating 100000 new byte from the heap the collector is started
Eclr.Environment.SetGcImplicit(100000);
}
}
else
{
// Set GC to explicit collection
if (Eclr.Environment.IsGcImplicit())
{
Eclr.Environment.SetGcExplicit();
}
}
}
IS_IMPLICITE = Eclr.Environment.IsGcImplicit();
ExecutePreviousState = EXECUTE;
}
}
}