0

I have attached my code below. I am trying to get the message box to go away after one pop up until another action within the application triggers it.

using (VIModel vi = new VIModel())
{
    var VideoFiles = vi.VI_VIDEO_FILES.Where(a => a.SEGMENT_ID == segmentId);
    foreach (var vf in VideoFiles)
    {
        string location = vf.URL;
        location = location.Replace('/', '\\');

        string[] smain = location.Split('\\');
        string unamemain = smain.Last().ToString();


        string fileToCopySource = Path.Combine(inputDirectory, location);
        string fileToCopyDestination = Path.Combine(outputDirectory, unamemain);

        foreach (char c in fileToCopySource)
        {
            if (fileToCopySource.Contains(c))
            {
                // notify user that the inputDirectory isn't valid
                MessageBox.Show("FOO");
            }
        }
        if (!File.Exists(fileToCopySource))
        {
            // notify user that file doesn't exist
            MessageBox.Show("FOO");
        }

        //File.Copy(inputDirectory + location, outputDirectory + unamemain, true);
        File.Copy(fileToCopySource, fileToCopyDestination, true);
        lbConsole.Items.Add("Moved " + location + " from: " + inputDirectory + " to " + fileToCopyDestination);
    }
}

1 Answer 1

3

Your code is alerting multiple times -- once for every "alertable" condition it finds, i.e. input directory not valid. What you need to do is record the fact that anything caused the condition that will need to be alerted, and then alert only once, outside of the loop:

bool needAlert = false;

foreach (char c in fileToCopySource)
{
    if (fileToCopySource.Contains(c))
    {
        needAlert = true;
        break; // no more looping needed.
    }
}

if(needAlert) MessageBox.Show("FOO"); // notify user that the inputDirectory isn't valid
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.