Shawn Swingler
Shawn Swingler

Reputation: 1

Alert email not working correctly

I am trying to send an email when the lastwritetime is more than 16 minutes. I want to loop through my files and check lastwritetime. When more than 16 minutes old send an email alert. I am looking to use the local or system time where the images are stored. I have gotten this far, but the system emails too often and it does not alert when I run a test and the images have not updated. What am I doing wrong?

try
{
    string files = @"\\cyclops-ch2-10\users\!SptEntEng\Desktop\ScreenScrapes\ChicagoSkyvision\ScreenScrape\ScreenScrape.png";
    string files1 = @"\\cyclops-ch2-10\users\!SptEntEng\Desktop\ScreenScrapes\ChicagoSeachange\ScreenScrape\ScreenScrape.png";
    string files2 = @"\\cyclops-ch2-10\users\!SptEntEng\Desktop\ScreenScrapes\IndianaSkyvision\ScreenScrape\ScreenScrape.png";
    string files3 = @"\\cyclops-ch2-10\users\!SptEntEng\Desktop\ScreenScrapes\IndianaSeachange\ScreenScrape\ScreenScrape.png";
    string files4 = @"\\cyclops-ch2-10\users\!SptEntEng\Desktop\ScreenScrapes\DetroitSkyvision\ScreenScrape\ScreenScrape.png";
    string files5 = @"\\cyclops-ch2-10\users\!SptEntEng\Desktop\ScreenScrapes\MichiganSeachange\ScreenScrape\ScreenScrape.png";
    string files6 = @"\\cyclops-ch2-10\users\!SptEntEng\Desktop\ScreenScrapes\LansingSkyvision\ScreenScrape\ScreenScrape.png";
    string files7 = @"\\cyclops-ch2-10\users\!SptEntEng\Desktop\ScreenScrapes\MinnesotaSeachange\ScreenScrape\ScreenScrape.png";
    string files8 = @"\\cyclops-ch2-10\users\!SptEntEng\Desktop\ScreenScrapes\HoustonSeachange\ScreenScrape\ScreenScrape.png";

    var FilePaths = new List<string>();
    FilePaths.Add(files);
    FilePaths.Add(files1);
    FilePaths.Add(files2);
    FilePaths.Add(files3);
    FilePaths.Add(files4);
    FilePaths.Add(files5);
    FilePaths.Add(files6);
    FilePaths.Add(files7);
    FilePaths.Add(files8);

    foreach (string file in FilePaths)
    {
        FileInfo fi = new FileInfo("ScreenScrape.png");
        if (fi.LastWriteTime < DateTime.Now.AddMinutes(16))
        {
            client.Send(CyclopsCentral);
            break;
        }
    }

Upvotes: 0

Views: 66

Answers (1)

Harsh
Harsh

Reputation: 3751

Your check will always be true as you are comparing to future time.

 if (fi.LastWriteTime < DateTime.Now.AddMinutes(16))

You need to change it to -16

 if (fi.LastWriteTime < DateTime.Now.AddMinutes(-16))

Upvotes: 4

Related Questions