|
|
I wonder if comparing the file's Created DateTime against the DateTime the event was called would do it. Maybe the file's DateTime isn't set until the copy is complete.
I'll have to try it
If it's not broken, fix it until it is
|
|
|
|
|
I know that LastWriteTime gets updated at file close, but I am not sure if it also gets updated on each write. Should not be too difficult to test.
|
|
|
|
|
|
I saw the first two, but not the last.
I need to spend more time reading before keyboarding again
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
what I tend to do when awaiting a large file is send two files, the one you are interested in, followed by a very small one (a sentinel) for which I order a FileSystemWatcher. Don't rely on file datetime stuff, as it depends on the actual file system, which could be a USB stick (often FAT), a network disk (might be UNIX based), etc.
|
|
|
|
|
Agreed. I've seen this approach used very successfully in several production scenarios across various systems.
|
|
|
|
|
yup - used to call this technique 'sentinel file' - very handy for processing a large data file being FTP'd to you from a mainframe, you get the mainframe to send you a small sentinel file and wait for that to kick off further processing
|
|
|
|
|
As you'll see, there are all sorts of solutions, and as JSOP points out (iirc), the notifications you get depend on the application thats creating/? the file
One strategy I used (when not using 'Sentinel Files' as per my comment to Luc), was to queue a notification from FileWatcher, and then periodically see if I could get exclusive access to the file and/or combine the notification with a dir list check - if so, she's good to go, if not, wait a period - not sure if JSOP outlined that sort of strategy
|
|
|
|
|
When .Length in the file's FileInfo is greater than 0 (and .Exists), the file has "arrived".
|
|
|
|
|
The file's size would be greater than 0 the moment Windows starts writing to it, and Exists would be true... But the file could still be in the process of being written.
If it's not broken, fix it until it is
|
|
|
|
|
|
Yes
The Size is the size of the file being copied, and it exists
If it's not broken, fix it until it is
|
|
|
|
|
Me too now ... Changed since I first used it 4 (?) years ago.
Did notice something else this time though (.NET 4.6):
Fires 3 events during the download:
1) Created
2) Changed
3) Changed
First 2 fired as soon as the download started; the last one (#3), corresponded to the download being complete.
|
|
|
|
|
Ya but the problem is that you never really know what event are going to fire. Different apps cause difference events to fire.
I'll probably do this in the Watcher events:
private FileWatcher_Changed(...)
{
while(!IsFileAvailable())
{
}
}
public bool IsFileAvailable(String sFilename)
{
bool results = false;
try
{
using (var inputStream = File.Open(sFilename, FileMode.Open, FileAccess.Read, FileShare.None))
{
results = inputStream.Length > 0;
}
}
catch (Exception)
{
results = false;
}
return results;
}
[UPDATE]
Just tried it. Worked fine.
If it's not broken, fix it until it is
|
|
|
|
|
I avoid tying up the file watcher by queueing the events and kicking off a background worker (if one isn't already running) to deal with the queued events. Better than polling (IMO).
|
|
|
|
|
Meaning each time the Changed is called you fire off a BG worker wait for the file to be done?
Makes sense.. Then multiple files can be handles at one time.
If it's not broken, fix it until it is
|
|
|
|
|
In my case, the BGW services the "queue"; and is only started by the file watcher if it is not running; and quits when the queue is empty.
You could start a new task for each new file; but will it scale? (I can even "serialize" my queue if I have to).
|
|
|
|
|
I think you've lost me here. Could you provide a small sample?
If it's not broken, fix it until it is
|
|
|
|
|
|
There are lots of workable solutions.
In my case, I was using a "Concurrent Queue" to add file names to (by file watcher), and that a BGW "pops" and services. The BGW starts and stops based on entries in the queue. The queue can be serialized and reloaded at start-up; with an initial BGW started in the process.
The above scenario is used by field equipment to upload field reports to SharePoint; while online or to synch later.
|
|
|
|
|
I ran into an oddity this afternoon, what I considered a trivial task turned out to be, well, a surprise.
I have this line:
string ditto = Path.Combine("f:\\tfs", "\\SomeDir\\NewBuild", "SomeFile.abc");
And what I get is this:
Quote: \SomeDir\NewBuild\SomeFile.abc
Can someone explain to me why it does not show as:
Quote: f:\tfs\SomeDir\NewBuild\SomeFile.abc
This happens in Microsoft Visual Studio Premium 2013, Version 12.0.31101.00 Update 4.
Project uses .NET Framework 4.5
|
|
|
|
|
|
Of course... I guess Friday is a good day to be "blind" for the obvious
Thank you
|
|
|
|
|
Hi,
class Program
{
static void Main(string[] args)
{
bool isPrime = true;
Console.WriteLine("Prime Numbers are:");
for (int i = 2; i <= 100; i++)
{
for (int j = 2; j <= 100; j++)
{
if (i != j && i % j == 0)
{
isPrime = false;
break;
}
}
if (isPrime)
{
Console.Write("\t"+i);
}
isPrime = true;
}
Console.ReadKey();
}
}
in this code,i didn't understand this line of code,Please explain me???
if (i != j && i % j == 0)
{
isPrime = false;
break;
}
what it means???
Thanks...
|
|
|
|