So with help of
@manchanx
we reached next steps:
1) The main culprit who has been released FileReader object and put it to the finalization stage was optimization that is turned on during Release and debug symbols are not emitted.
That is why during the active workflow in the PerformRead method and at first glance preserving all references alive , the GC treated FileReader fr object as a garbage
and submit it to the finalization stage.
So to eliminate such issue there are 3 steps:
1) Apply [MethodImplAttribute(MethodImplOptions.NoInlining)] to both Main and Read methods.
2) Operate fr reference as much as possible: for example add next lines:
class Program
{
static void Main(string[] args)
{
FileReader fr = new FileReader("myfile.txt");
fr.Read();
Console.WriteLine(fr.GetType());
}
}
3) Add next setting file [assemblyname].ini
With these settings, your app runs at full speed. When you want to debug your app by turning on debug tracking and possibly turning off (CIL) code optimization, just use the following settings:
The content of a file is next:
[.NET Framework Debugging Control]
GenerateTrackingInfo=1
AllowOptimize=0