Севікс
Севікс
CC#
Created by Севікс on 2/1/2025 in #help
Immediately delete image file after it being closed
In my program i have byte[] imgSource. I create image file in temp folder:
c#
if (container != null)
{
string tempFileName = Path.Combine(Path.GetTempPath(), $"tempImage_{Guid.NewGuid()}_{DateTime.Now.Ticks}.png");

using (FileStream fs = new FileStream(tempFileName, FileMode.Create, FileAccess.Write, FileShare.None))
{
fs.Write(container, 0, container.Length);
}
c#
if (container != null)
{
string tempFileName = Path.Combine(Path.GetTempPath(), $"tempImage_{Guid.NewGuid()}_{DateTime.Now.Ticks}.png");

using (FileStream fs = new FileStream(tempFileName, FileMode.Create, FileAccess.Write, FileShare.None))
{
fs.Write(container, 0, container.Length);
}
Then idk how, but it need to be opened, and delete itself after being closed, i coded this, but it doesn't work:
c#
Thread thread = new Thread(() =>
{
Process process = new Process();
process.StartInfo.FileName = tempFileName;
process.StartInfo.UseShellExecute = true;
process.EnableRaisingEvents = true;
process.Exited += (s, args) =>
{
try
{
File.Delete(tempFileName);
}
catch (Exception ex)
{
Console.WriteLine($"Failed to delete temp file: {ex.Message}");
}
};
process.Start();
});
thread.Start();
}
c#
Thread thread = new Thread(() =>
{
Process process = new Process();
process.StartInfo.FileName = tempFileName;
process.StartInfo.UseShellExecute = true;
process.EnableRaisingEvents = true;
process.Exited += (s, args) =>
{
try
{
File.Delete(tempFileName);
}
catch (Exception ex)
{
Console.WriteLine($"Failed to delete temp file: {ex.Message}");
}
};
process.Start();
});
thread.Start();
}
Idk why, but it delete itself immediately after being opened, or sometimes before it
2 replies
CC#
Created by Севікс on 7/30/2024 in #help
WinForms problem with SQLite
No description
9 replies