How to update UI control from other thread in WPF ?

In WPF – Other threads cannot directly update the UI Controls so the question is what are the alternatives or ways if we want so.
So there are some ways to achieve this, One of them is through Dispatcher and BackgroundWorker Thread.

I am discussing here how you can achieve your goal by using Dispatcher thread.

this.Dispatcher.BeginInvoke(new Action(() =>
            {
                txtName.Text = "Hi  Tester";
            }));
			
//OR
			 new Thread(() =>
            {               
                this.Dispatcher.BeginInvoke(new Action(() =>
                {
                    txtName.Text = "Hi Tester";
                }
                    ));
            }
            ).Start();

FULL EXAMPLE

<Window x:Class="UIControlupdatefromOtherThread.MainWindow"
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	Title="UI" Height="350″ Width="525″ Background="#98dafc">
	<Grid>
		<StackPanel Margin="20,50″>
			<TextBox x:Name="txtName" Text="Hi Developers" Width="300″ FontStyle="Italic" FontWeight="Bold" FontSize="20″ />
		</StackPanel>
		<Button x:Name="btn" Height="30″ Width="200″ Content="Click -UI Control Update" Click="btn_Click" />
	</Grid>
</Window>




using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;

namespace UIControlupdatefromOtherThread
{
    /// Interaction logic for MainWindow.xaml
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private void btn_Click(object sender, RoutedEventArgs e)
        {
            CallingDispatcherFunction();
        }

        private void CallingDispatcherFunction()
        {
            //SUCCESS – while Updating UI control with Dispatcher

            //Thread thread2 = new Thread(UpdateControlDispatcher);
            //thread2.Start();

            //SUCCESS – while Updating UI control with Dispatcher : Other short way

            new Thread(() =>
            {
                this.Dispatcher.BeginInvoke(new Action(() =>
                {
                    txtName.Text = "Hi Tester";
                }
                ));
            }
            ).Start();

            // ERROR – while Updating UI control from other thread without dispatcher

            //Thread thread1 = new Thread(UpdateControl);
            //thread1.Start();

            // OR – ERROR – while Updating UI control – Other way to write above 2 lines

            //new Thread(() =>
            //{
            // txtName.Text = "Hi Tester";
            //}).Start();
        }

        public void UpdateControl()
        {
            txtName.Text = "Hi Tester";
        }
        public void UpdateControlDispatcher()
        {
            this.Dispatcher.BeginInvoke(new Action(() =>
            {
                txtName.Text = "Hi Tester";
            }));
        }
    }
}