tracking file size change in C#
c#
Solution
Use the `FileSystemWatcher` to watch for changes to your file. When it changes, get the size. For example:
var fsw = new FileSystemWatcher(@"C:\pathtoyourfile");
fsw.Changed += TheFileChanged;
private void TheFileChanged(object sender, FileSystemEventArgs e)
{
if (e.ChangeType == WatcherChangeTypes.Changed)
{
var info = new FileInfo(e.FullPath);
var theSize = info.Length;
}
}
When you are done watching for changes, dispose of your FileSystemWatcher.
Problem
Possible Duplicate: C# get file change events i want to track a specific file size when it reach a specific size using C# is there a way to add event handler on file size change or do i need to run an infinite process in thread that keeps checking the file size ? thanks