I am trying to update the UI form different class which is inside a thread.
Relevant code is:
MainWindow.xaml.cs
private void encryptButtonPressed(object sender, RoutedEventArgs e)
{
    if (checkValues() == true)
    {
        updateConsole("Starting Encryption...");
        Thread encryptThread = new Thread(encrypt);
        encryptThread.Start();
    }
}
encrypt function
public void encrypt()
{
    Encrypt encrypt = new Encrypt(this.KeyFileContent, this.SourcePath, this.DestinationPath, this);
    encrypt.start();
}
update console function
public void updateConsole(String text)
{
    consoleWindow.AppendText(Environment.NewLine);
    consoleWindow.AppendText(text);
    consoleWindow.ScrollToEnd();
}
Encrypt.cs
public byte[] key;
public String source;
public String destination;
public MainWindow mainWindow;
public Encrypt(byte[] key, String source, String destination, MainWindow mainWindow) 
{
    this.key = key;
    this.source = source;
    this.destination = destination;
    this.mainWindow = mainWindow;
}
start function
public void start()
{
    mainWindow.updateConsole("Updating form thread");
}
I have tried
Dispatcher.Invoke(() =>
    {
        mainWindow.updateConsole("Updating form thread");
    });
but no use.
 
     
    