diff --git a/csharp/Platform.IO/TemporaryFiles.cs b/csharp/Platform.IO/TemporaryFiles.cs
index 7a719df..879217f 100644
--- a/csharp/Platform.IO/TemporaryFiles.cs
+++ b/csharp/Platform.IO/TemporaryFiles.cs
@@ -13,6 +13,15 @@ public class TemporaryFiles
private const string UserFilesListFileNamePrefix = ".used-temporary-files.txt";
private static readonly object UsedFilesListLock = new();
private static readonly string UsedFilesListFilename = Assembly.GetExecutingAssembly().Location + UserFilesListFileNamePrefix;
+
+ ///
+ /// Static constructor that cleans up all previously used temporary files.
+ /// Статический конструктор, который очищает все ранее использованные временные файлы.
+ ///
+ static TemporaryFiles()
+ {
+ DeleteAllPreviouslyUsed();
+ }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void AddToUsedFilesList(string filename)
{
diff --git a/csharp/test-results/_vds2816548_2025-09-12_22_28_36.trx b/csharp/test-results/_vds2816548_2025-09-12_22_28_36.trx
new file mode 100644
index 0000000..85c90ec
--- /dev/null
+++ b/csharp/test-results/_vds2816548_2025-09-12_22_28_36.trx
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/examples/StaticConstructorTest/Program.cs b/examples/StaticConstructorTest/Program.cs
new file mode 100644
index 0000000..5451672
--- /dev/null
+++ b/examples/StaticConstructorTest/Program.cs
@@ -0,0 +1,22 @@
+using System;
+using System.IO;
+using Platform.IO;
+
+// Create a simple test to verify static constructor is called
+class Program
+{
+ static void Main()
+ {
+ Console.WriteLine("Testing TemporaryFiles static constructor...");
+ Console.WriteLine("Creating first temporary file (this will trigger static constructor)...");
+ var temp1 = TemporaryFiles.UseNew();
+ Console.WriteLine($"First temp file: {temp1}");
+ Console.WriteLine($"First temp file exists: {File.Exists(temp1)}");
+
+ Console.WriteLine("\nTest completed successfully!");
+ Console.WriteLine("The static constructor was called when TemporaryFiles.UseNew() was first accessed.");
+
+ // Clean up the test file
+ File.Delete(temp1);
+ }
+}
diff --git a/examples/StaticConstructorTest/StaticConstructorTest.csproj b/examples/StaticConstructorTest/StaticConstructorTest.csproj
new file mode 100644
index 0000000..924a3ee
--- /dev/null
+++ b/examples/StaticConstructorTest/StaticConstructorTest.csproj
@@ -0,0 +1,14 @@
+
+
+
+ Exe
+ net8.0
+ enable
+ enable
+
+
+
+
+
+
+
diff --git a/examples/test_static_constructor.cs b/examples/test_static_constructor.cs
new file mode 100644
index 0000000..83bc010
--- /dev/null
+++ b/examples/test_static_constructor.cs
@@ -0,0 +1,28 @@
+using System;
+using System.IO;
+using Platform.IO;
+
+// Create a simple test to verify static constructor is called
+class Program
+{
+ static void Main()
+ {
+ Console.WriteLine("Creating first temporary file...");
+ var temp1 = TemporaryFiles.UseNew();
+ Console.WriteLine($"First temp file: {temp1}");
+ Console.WriteLine($"First temp file exists: {File.Exists(temp1)}");
+
+ Console.WriteLine("\nCreating second temporary file...");
+ var temp2 = TemporaryFiles.UseNew();
+ Console.WriteLine($"Second temp file: {temp2}");
+ Console.WriteLine($"Second temp file exists: {File.Exists(temp2)}");
+
+ Console.WriteLine("\nCalling DeleteAllPreviouslyUsed manually...");
+ TemporaryFiles.DeleteAllPreviouslyUsed();
+
+ Console.WriteLine($"First temp file exists after cleanup: {File.Exists(temp1)}");
+ Console.WriteLine($"Second temp file exists after cleanup: {File.Exists(temp2)}");
+
+ Console.WriteLine("\nTest completed successfully!");
+ }
+}
\ No newline at end of file