Click here to Skip to main content
15,886,664 members
Home / Discussions / C#
   

C#

 
GeneralRe: Capture a image fram from a local video using a button to transfer into a picturebox and then save into local disk in C#.NET Pin
Richard MacCutchan24-Feb-16 1:16
mveRichard MacCutchan24-Feb-16 1:16 
AnswerRe: Capture a image fram from a local video using a button to transfer into a picturebox and then save into local disk in C#.NET Pin
Gerry Schmitz24-Feb-16 6:57
mveGerry Schmitz24-Feb-16 6:57 
QuestionDispose of RX subscriptions Pin
Kenneth Haugland23-Feb-16 2:28
mvaKenneth Haugland23-Feb-16 2:28 
AnswerRe: Dispose of RX subscriptions Pin
Kenneth Haugland23-Feb-16 2:32
mvaKenneth Haugland23-Feb-16 2:32 
Questionhello guys I have a problem in my string cmd.... Pin
Member 1217509322-Feb-16 22:59
Member 1217509322-Feb-16 22:59 
AnswerRe: hello guys I have a problem in my string cmd.... Pin
Pete O'Hanlon22-Feb-16 23:41
mvePete O'Hanlon22-Feb-16 23:41 
AnswerRe: hello guys I have a problem in my string cmd.... Pin
OriginalGriff22-Feb-16 23:52
mveOriginalGriff22-Feb-16 23:52 
QuestionFileSystemWatcher Problem - My Solution Pin
Kevin Marois22-Feb-16 10:51
professionalKevin Marois22-Feb-16 10:51 
The other day I posted about a problem[^] with FileSystemWatcher raising events before the file is completely copied into the watched folder.

Thanks for Gerry Schmitz[^] I think I've come up with a workable solution:

I would appreciate any comments on this idea.

[1] The FileSystemWatcher detects the file. It's a large file that take a while to get fully copied into the folder:
/// <summary>
/// Handles the FileSystemWatcher's Created event. This is fired when a file starts being 
/// copied into the target folder
/// </summary>
private void OnCreated(object sender, FileSystemEventArgs e)
{
    if (HasAnotherFileEventOccuredRecently(e.FullPath))
    {
        return;
    }

    QueueFile(e);
}

The HasAnotherFileEventOccuredRecently method is called to see if this is the first time a FileSystemWatcher event has been raised for the file. Multiple events are raised for the file, so if any events for the file have already been called, then ignore them. I didn't include this code for brevity.

[2] Next QueueFile is called:
/// <summary>
/// Places a file in the queue of files waiting for to become ready
/// </summary>
private void QueueFile(FileSystemEventArgs fileSystemEventArgs)
{
    var worker = new BackgroundWorker();
    worker.DoWork += Worker_DoWork;
    worker.RunWorkerCompleted += Worker_RunWorkerCompleted;

    _queue.Add(worker);

    worker.RunWorkerAsync(fileSystemEventArgs);
}

The BG Worker snippets...
private void Worker_DoWork(object sender, DoWorkEventArgs e)
{
    var args = (FileSystemEventArgs)e.Argument;

    if (args != null)
    {
        while (!IsFileAvailable(args.FullPath))
        {
            // Loop until the file is read/write
        }
    }

    e.Result = args;
}

and
private void Worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
    var args = (FileSystemEventArgs)e.Result;

    // Remove the worker from the queue
    var worker = _queue.FirstOrDefault(x => x == sender);
    if (worker != null)
    {
        worker.Dispose();
        _queue.Remove(worker);
    }

    // Raise the event so listeners off this class are notified when the 
    // file is ready to process
    this.OnCreated(args);
}

[3] and finally the IsFileAvailable method:
/// <summary>
/// Determines whether a file is available for Read/Write.
/// </summary>
public bool IsFileAvailable(string filename)
{
    var results = false;

    try
    {
        using (var inputStream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.None))
        {
            results = inputStream.Length > 0;
        }
    }
    catch (Exception)
    {
        results = false;
    }

    return results;
}
If it's not broken, fix it until it is


modified 22-Feb-16 16:59pm.

AnswerRe: FileSystemWatcher Problem - My Solution Pin
Garth J Lancaster22-Feb-16 18:37
professionalGarth J Lancaster22-Feb-16 18:37 
QuestionSQL SERVER Instance Pin
jackie.398122-Feb-16 3:39
jackie.398122-Feb-16 3:39 
AnswerRe: SQL SERVER Instance Pin
OriginalGriff22-Feb-16 4:06
mveOriginalGriff22-Feb-16 4:06 
GeneralRe: SQL SERVER Instance Pin
jackie.398122-Feb-16 4:15
jackie.398122-Feb-16 4:15 
GeneralRe: SQL SERVER Instance Pin
OriginalGriff22-Feb-16 5:01
mveOriginalGriff22-Feb-16 5:01 
GeneralRe: SQL SERVER Instance Pin
jackie.398122-Feb-16 5:14
jackie.398122-Feb-16 5:14 
GeneralRe: SQL SERVER Instance Pin
OriginalGriff22-Feb-16 6:03
mveOriginalGriff22-Feb-16 6:03 
GeneralRe: SQL SERVER Instance Pin
jackie.398122-Feb-16 6:14
jackie.398122-Feb-16 6:14 
AnswerRe: SQL SERVER Instance Pin
Richard Deeming22-Feb-16 8:07
mveRichard Deeming22-Feb-16 8:07 
GeneralRe: SQL SERVER Instance Pin
OriginalGriff22-Feb-16 8:22
mveOriginalGriff22-Feb-16 8:22 
Questionrun-time "cost" (speed ? memory ?) of resetting a DataSource in order to refresh bound UI Controls ? Pin
BillWoodruff22-Feb-16 0:19
professionalBillWoodruff22-Feb-16 0:19 
AnswerRe: run-time "cost" (speed ? memory ?) of resetting a DataSource in order to refresh bound UI Controls ? Pin
Richard Deeming22-Feb-16 2:05
mveRichard Deeming22-Feb-16 2:05 
GeneralRe: run-time "cost" (speed ? memory ?) of resetting a DataSource in order to refresh bound UI Controls ? Pin
BillWoodruff22-Feb-16 3:12
professionalBillWoodruff22-Feb-16 3:12 
QuestionCan BHO(browser helper object) remove readonly attribute of an input Pin
Edward_Zhao21-Feb-16 17:36
professionalEdward_Zhao21-Feb-16 17:36 
AnswerRe: Can BHO(browser helper object) remove readonly attribute of an input Pin
Kornfeld Eliyahu Peter21-Feb-16 20:42
professionalKornfeld Eliyahu Peter21-Feb-16 20:42 
AnswerRe: Can BHO(browser helper object) remove readonly attribute of an input Pin
Pete O'Hanlon21-Feb-16 20:51
mvePete O'Hanlon21-Feb-16 20:51 
Questionhello guys I have a Question, how to display the result from this program in richtextbox when I push a buttom Pin
Member 1217509321-Feb-16 4:40
Member 1217509321-Feb-16 4:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.