I'm new here and new to C#. I work for a retailer and have been stuck in visual studio 6 until this year but now I'm self-teaching c# and rewriting everything that I've done for the past 21 years. Don't you wish you were me? :{
Anyway, I have a Windows service that periodically executes a series of jobs that create files. When those jobs complete, the service creates a zip file from them and notifies a server at corporate to collect and delete the zip file. I've been struggling with this service for a couple of days now because the timer event won't fire. So I stripped it down to bare metal -- a timer and an event handler -- and that worked. I then started adding back in the worker code a little at a time until I narrowed down to the section of code that is causing the issue. It's the ZipArchive call. Everything works until I uncomment the following code, specifically the "using ( var archive ... ))" block
var transmissionFiles = Directory.GetFiles( _uploadDirectory, "*.trx" );
if (transmissionFiles.Length > 0)
{
using (var zipfile = new FileStream( $"{_uploadDirectory}zp" +
$"{DateTime.Now:yyyyMMdd}.{_storeNumber:D4}.{DateTime.Now:HHmmss}", FileMode.Open ))
{
using (var archive = new ZipArchive( zipfile, ZipArchiveMode.Update ))
{
foreach (var tFile in transmissionFiles)
{
archive.CreateEntry( tFile );
File.Delete( tFile );
}
}
}
}
Resolved by moving the ZipArchive references to a separate method. Something about having those calls in the timer event handler is not working. Weird