C# WPF Unable to control Textboxes
        Posted  
        
            by 
                Bo0m3r
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Bo0m3r
        
        
        
        Published on 2012-10-03T14:55:25Z
        Indexed on 
            2012/10/03
            15:37 UTC
        
        
        Read the original article
        Hit count: 189
        
I'm a beginner in coding into C#. While I'm launching a process I can't controls my textboxes. I found some answers on this forum but the explaination is a bit to difficult for me to implement it for my problem.
I created a small program that will run a batch file to make a backup. While the backup is running I can't modify my textboxes, disabling buttons etc... I already saw that this is normal but I don't know how to implement the solutions. My last attempt was with Dispatcher.invoke as you can see below.
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        tb_Status.Text = "Ready";
    }
    public void status()
    {
       Dispatcher.Invoke(DispatcherPriority.Send, new Action( () => { tb_Status.Text = "The backup is running!"; } ) );
    }
    public void process()
    {
        try
        {            
            Process p = new Process();
            p.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
            p.StartInfo.CreateNoWindow = true;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.FileName = "Robocopy.bat";
            p.Start();
            string output = p.StandardOutput.ReadToEnd();
            p.WaitForExit();
            tb_Output.Text = File.ReadAllText("Backup\\log.txt");
        }
        catch (Exception ex)
        {
            tb_Status.Text = ex.Message.ToString();
        }
    }
    private void Bt_Start_Click(object sender, EventArgs e)
    {
        status();
        Directory.CreateDirectory("Backup");
        process();
        tb_Status.Text = "The backup finished";
        File.Delete("Backup\\log.txt");
    }
}
}
Any help is appreciated!
© Stack Overflow or respective owner