Member Avatar for Member #632324
Member #632324

Greetings,

I want to develop a program to check if my computer dowloads any file and after completion of the download it should inform me. Is there any .dll file method or any thing you can tell me to use or to follow. What should I do for this?

Thanks

Dani AI

Generated

For @m.a.u.: a reliable, practical way in C# is to watch the Downloads folder for new files and then confirm a file is finished by either (a) trying to open it with exclusive access or (b) checking that its size/last‑write time stays stable for a short interval. Use FileSystemWatcher to detect Created/Changed events; for Windows background transfers (BITS) use the BITS API if the transfer comes from a service that uses it. See the .NET FileSystemWatcher docs and the BITS overview for implementation details (FileSystemWatcher, BITS overview).

Example approach (sketch):

  • Start a FileSystemWatcher on the target folder(s).
  • On Created, spawn a Task that loops:
    • Try to open the file with FileShare.None. If open succeeds, assume completed.
    • Otherwise, record file size, wait a second, recheck; if size is unchanged for N iterations, assume completed.
  • Notify the user when completion is detected.

A short C# sketch:

// on Created event:
Task.Run(async () =>
{
    const int maxAttempts = 30, delayMs = 1000;
    long lastSize = -1;
    for (int i = 0; i < maxAttempts; i++)
    {
        try { using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.None)) break; }
        catch { /* still writing */ }
        long size = new FileInfo(path).Length;
        if (size == lastSize) break;
        lastSize = size;
        await Task.Delay(delayMs);
    }
    // notify completed
});

Cautions: monitor only needed folders (performance), account for browser temp extensions (e.g., browsers often write to temporary names), and remember some apps stream to memory or use custom temp paths—those cases need app-specific hooks or a system-level filter.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.