I'm developing a Windows program that interacts with a physical machine via TCP, and pulls data from it.
The data more specifically is represented by a class, let's say MachineData
:
readonly public struct MachineData
{
readonly double X;
readonly double Y;
readonly double Z;
readonly long feedrate;
readonly ulong timestamp;
readonly ulong id;
readonly int laserPower;
readonly int spotArea;
readonly int spotWidth;
public MachineData(double x, double y, double z, long _feedrate, ulong _timestamp, ulong _id, int _laserPower, int _spotArea, int _spotWidth)
{
X = x;
Y = y;
Z = z;
feedrate = _feedrate;
timestamp = _timestamp;
id = _id;
spotArea = _spotArea;
spotWidth = _spotWidth;
laserPower = _laserPower;
}
public string ToCSV()
{
try
{
return String.Format(CultureInfo.InvariantCulture.NumberFormat, "{0},{1},{2:0.000},{3:0.000},{4:0.000},{5},{6},{7},{8}\n", id, timestamp, X, Y, Z, feedrate, laserPower, spotArea, spotWidth);
}
catch
{
return "ERROR";
}
}
public override string ToString()
{
return String.Format("X: {0:0.000} Y: {1:0.000} Z: {2:0.000} Feedrate: {3} Timestamp: {4} ID: {5} Laser: {6}, Spot Area: {7}, Spot Width: {8}", X, Y, Z, feedrate, timestamp, id, laserPower, spotArea, spotWidth);
}
}
So I have one thread pulling data, and enqueuing it in a ConcurrentQueue<MachineData>
data structure.
This MachineData
class has a ToCSV()
method that formats it in the export format. This method is basically:
public string ToCSV()
{
try
{
return String.Format(CultureInfo.InvariantCulture.NumberFormat, "{0},{1},{2:0.000},{3:0.000},{4:0.000},{5},{6},{7},{8}\n", id, timestamp, X, Y, Z, feedrate, laserPower, spotArea, spotWidth);
}
catch
{
return "ERROR";
}
}
Another thread is dequeuing the data and writing it to a file. When the program runs for about 3 minutes, it crashes with the error:
Fatal error. Internal CLR error. (0x80131506)
when on .NET Core 3.1. The Windows debugger points the error to that line:
return String.Format(CultureInfo.InvariantCulture.NumberFormat, "{0},{1},{2:0.000},{3:0.000},{4:0.000},{5},{6},{7},{8}\n", id, timestamp, X, Y, Z, feedrate, laserPower, spotArea, spotWidth);
I have no idea. Anyone could help me?