Avatar of chuang4630
chuang4630

asked on 

What is the alternative of Dispatcher in Winform

I am working on the Winform project (DevExpress).  I need to port some of the code from a functional equivalent WPF project into this Winform project. The WPF project uses:

1. Dispatcher.Invoke
Dispatcher.Invoke(new del(delegate()
            {
                CheckBox headerCheckBox = (CheckBox)GetChildControl(TagResults.dgTagResults, "headerCheckBox");
                headerCheckBox.IsEnabled = value;
            }));

2. New thread and Dispatcher.BeginInvoke()


                    Thread updateTrd = new Thread(delegate()
                    {
                        try
                        {
                            prgStart = true;
                            Dispatcher.BeginInvoke(new ThreadStart(delegate()
                                {
                                    SetControls();
                                }));

                            // Update the firmware Update status
                            Dispatcher.Invoke(new del2(updateStatus));
                        }
                        catch (Exception ex)
                        {
                            SetFailedStatus();
                            if (ex is FAULT_BL_INVALID_IMAGE_CRC_Exception)
                            {
                                if (isFirmwareUpdateFailed)
                                {
                                    //Firmware Update failed, disconnect the reader.
                                    Dispatcher.BeginInvoke(new ThreadStart(delegate() {
                                        btnConnect_Click(this, new RoutedEventArgs()); }));
                                }
                                this.Dispatcher.BeginInvoke(new ThreadStart(delegate()
                                {
                                    SetControls2();
                                }));
                            }
                            else
                            {
                                this.Dispatcher.BeginInvoke(new ThreadStart(delegate()
                                {
                                    SetControls3();
                                }));
                            }
                            updateFailedStatus();
                        }
                        finally
                        {

                        }
                    });
                    updateTrd.Start();

What would be the equivalent and / or better coding pattern that I should follow?

Big thanks.
.NET ProgrammingC#

Avatar of undefined
Last Comment
chuang4630

8/22/2022 - Mon