private void DoWork(string operation)
        {
            TryAgain :;
            try
            {
                int dotCount = 0;
                FilesCount = 0;
                Thread thread = new Thread(() => FileCounter())
                {
                    IsBackground = true
                };
                thread.Start();
                progressBar1.Value = 0;
                current            = 0;

                if (operation == Resources.FirewallArgs && RootPath != null)
                {
                    while (CountingFilesOperation)
                    {
                        Thread.Sleep(500);
                        Console.WriteLine(Resources.CountingFiles);
                        dotCount++;
                        if (dotCount == 2)
                        {
                            label1.Text = Operation;
                        }
                        if (dotCount == 4)
                        {
                            label1.Text = Operation + ".";
                        }
                        if (dotCount == 6)
                        {
                            label1.Text = Operation + "..";
                        }
                        if (dotCount == 8)
                        {
                            label1.Text = Operation + "...";
                            dotCount    = 0;
                        }
                        Application.DoEvents();
                    }
                    label1.Text = Resources.Blocking + Resources.outbound;
                    foreach (string item in RootPath)
                    {
                        try
                        {
                            while (PauseOperation)
                            {
                                Thread.Sleep(500);
                            }
                            current++;
                            string path      = Path.GetDirectoryName(item);
                            string title     = Path.GetFileName(path) + " - " + Path.GetFileName(item);
                            string arguments = "advfirewall firewall add rule name=" + "\"" + MainFolderName + " - " + title + "\"" + " dir=out program=" + "\"" + item + "\"" + " action=block";
                            progressBar1.Value = (current * 100) / FilesCount;
                            try
                            {
                                this.Text = Resources.BlockingFilesTitle + progressBar1.Value + Resources.Percentage;
                            }
                            catch (ArgumentOutOfRangeException)
                            {
                                continue;
                            }
                            label2.Text = Path.GetFileName(item);
                            Application.DoEvents();
                            StartProcess.StartInfo("netsh.exe", arguments, true, true, true);
                        }
                        catch (ArgumentOutOfRangeException)
                        {
                            continue;
                        }
                    }
                    current            = 0;
                    progressBar1.Value = 0;
                    label1.Text        = Resources.Blocking + Resources.inbound;
                    foreach (string item in RootPath)
                    {
                        try
                        {
                            while (PauseOperation)
                            {
                                Thread.Sleep(500);
                            }
                            current++;
                            string path      = Path.GetDirectoryName(item);
                            string title     = Path.GetFileName(path) + " - " + Path.GetFileName(item);
                            string arguments = "advfirewall firewall add rule name=" + "\"" + MainFolderName + " - " + title + "\"" + " dir=in program=" + "\"" + item + "\"" + " action=block";
                            progressBar1.Value = (current * 100) / FilesCount;
                            try
                            {
                                this.Text = Resources.BlockingFilesTitle + progressBar1.Value + Resources.Percentage;
                            }
                            catch (ArgumentOutOfRangeException)
                            {
                                continue;
                            }
                            label2.Text = Path.GetFileName(item);
                            Application.DoEvents();
                            StartProcess.StartInfo("netsh.exe", arguments, true, true, true);
                        }
                        catch (ArgumentOutOfRangeException)
                        {
                            continue;
                        }
                    }
                    Thread.Sleep(1500);
                    if (current > 0 && NoMoreThreads)
                    {
                        Hide();

                        DialogResult results = MessageForm(Resources.DialogMessageBlockFolder, Resources.DialogTitleSuccess, MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2);
                        if (results == DialogResult.Yes)
                        {
                            StartProcess.StartInfo("wf.msc");
                        }
                    }
                    else if (current == 0)
                    {
                        Hide();

                        MessageForm(Resources.DialogMessageFail, Resources.DialogTitleFail, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                ThreadRunning = false;
                if (NoMoreThreads)
                {
                    ExplorerRefresh.RefreshWindowsExplorer();
                    Environment.Exit(0);
                }
            }
            catch (Exception ex)
            {
                var dialog = MessageBox.Show("Too many errors have occured. Please close any programs that may be locking the files in the queue or reboot Windows and try again." + Environment.NewLine + Environment.NewLine + "The exact error message is: " + ex.Message + Environment.NewLine + Environment.NewLine + "Would you like to continue anyway?", Resources.ErrorTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                if (dialog == DialogResult.Yes)
                {
                    goto TryAgain;
                }
                else if (dialog == DialogResult.No)
                {
                    Environment.Exit(0);
                }
            }
        }
 private void AttributesMenu_FormClosing(object sender, FormClosingEventArgs e)
 {
     Hide();
     Thread.Sleep(250);
     ExplorerRefresh.RefreshWindowsExplorer();
 }
        public Main(string[] args)
        {
            try
            {
                InitializeComponent();

                if (args.Length == 0)
                {
                    Settings settings = new Settings();
                    using (settings)
                    {
                        settings.ShowDialog();
                    }
                }
                if (args.Length > 0)
                {
                    // Refresh Explorer
                    if (args[0] == Resources.RefreshArgs)
                    {
                        ExplorerRefresh.RefreshWindowsExplorer();
                    }
                    // Install
                    if (args[0] == Resources.InstallArgs)
                    {
                        if (IsElevated)
                        {
                            InstallerElevated();
                        }
                        else
                        {
                            InstallerUnelevated();
                        }
                    }
                    // Uninstall
                    if (args[0] == Resources.UninstallArgs)
                    {
                        if (IsElevated)
                        {
                            InstallerElevated();
                        }
                        else
                        {
                            InstallerUnelevated();
                        }
                    }
                    // Settings
                    if (args[0] == Resources.SettingArgs)
                    {
                        Settings settings = new Settings();
                        using (settings)
                        {
                            settings.ShowDialog();
                        }
                    }
                }
                if (args.Length > 1)
                {
                    ExecuteCommands(args);
                }
                if (!KeepAlive)
                {
                    Environment.Exit(0);
                }
            }
            catch (Exception ex)
            {
                MessageForm(ex.GetBaseException() + Environment.NewLine + ex.TargetSite, ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);

                Environment.Exit(0);
            }
        }
 private void Button1_Click(object sender, EventArgs e)
 {
     ExplorerRefresh.RefreshWindowsExplorer();
 }