get Time

computer

New member
Joined
Jul 1, 2016
Messages
1
Programming Experience
Beginner
I try to create app . scenario is i have a folder in that folder there is some files so every file is taking update in every 15 mint check image
in image currenlt there is 3 files so every file update in every 5 seconds when this fully update then next file is create so i want when there is no update in file in every 5 seconds then i want to insert data in table otherwise not
i try this
public static void Main()
{

while (true)
{
try
{
string abcPath, defPath = "";
abcPath
= ConfigurationManager.AppSettings.Get("abcPath");
defPath
= ConfigurationManager.AppSettings.Get("defPath");
DateTime abc = File.GetLastAccessTime(abcPath);
DateTime def = File.GetLastAccessTime(defPath);
Console.WriteLine("the last access time for abc{0}", abc);
Console.WriteLine("the last access time for def{0}", def);
TimeSpan timediff = DateTime.Now - abc;
TimeSpan timediff1 = DateTime.Now - def;
if( timediff.TotalMinutes > 5)
{
DataClasses1DataContext db = new DataClasses1DataContext();
var u = db.tbl_urgent_contacts;
foreach (var a in u)
{
tbl_OutBox tb
= new tbl_OutBox();
tb
.FromSIM_No = a.SimNo;
tb
.ToSIM_No = a.SimNo;
tb
.ToText = "Check abc";
tb
.Reply = "NA";
tb
.Response = "NA";
tb
.RegNo = "NA";
tb
.Datetd = DateTime.Now;
tb
.FFID = "NA";
tb
.UserId = "You";
tb
.FromText = "Check abc";
db
.tbl_OutBoxes.InsertOnSubmit(tb);
db
.SubmitChanges();
}
}
if (timediff1.TotalMinutes > 5)
{
DataClasses1DataContext db = new DataClasses1DataContext();
var u = db.tbl_urgent_contacts;
foreach (var a in u)
{
tbl_OutBox tb
= new tbl_OutBox();
tb
.FromSIM_No = a.SimNo;
tb
.ToSIM_No = a.SimNo;
tb
.ToText = "Check def";
tb
.Reply = "NA";
tb
.Response = "NA";
tb
.RegNo = "NA";
tb
.Datetd = DateTime.Now;
tb
.FFID = "NA";
tb
.UserId = "You";
tb
.FromText = "Check def";
db
.tbl_OutBoxes.InsertOnSubmit(tb);
db
.SubmitChanges();
}

}


}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
Thread.Sleep(4000);
}
}when i try this and when i set breakpoint i see that within 5 seconds data is send to table where as i want after seconds data is send to table when there is no update in file any solution
 
Last edited:

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,813
Location
Sydney, Australia
Programming Experience
10+
For future reference, please don't post code snippets as HTML. As you can see, you lose the indenting and that makes it hard to read. Please post it as plain text between formatting tags, i.e.

[xcode=c#]your code here[/xcode]
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,813
Location
Sydney, Australia
Programming Experience
10+
I'm not 100% sure what the issue is but you seem to be saying that you want to retrieve the data from a file once it is no longer being updated. If so then here's an example you can work from.
private Dictionary<string, DateTime> modifiedTimesByFileName = new Dictionary<string, DateTime>();

private void Timer1_Tick(object sender, EventArgs e)
{
    foreach (var fileName in Directory.GetFiles(folderPath).Select(s => Path.GetFileName(s)))
    {
        var modifiedTime = File.GetLastModifiedTime(fileName);

        if (modifiedTimesByFileName.ContainsKey(fileName))
        {
            if (modifiedTime == modifiedTimesByFileName[fileName])
            {
                // No change since last check.
                
                // Process file here.

                modifiedTimesByFileName.Remove(fileName);
            }
            else
            {
                // File updated.
                modifiedTimesByFileName[fileName] = modifiedTime;
            }
        }
        else
        {
            // New file.
            modifiedTimesByFileName.Add(fileName, modifiedTime);
        }
    }
}
 
Top Bottom