Wednesday, March 27, 2013

The calling thread must be STA, because many UI components require this. in WPF.


I faced this issue while opening my window in WPF application.  After spending some hour on Google found I got this work around.

[STAThread]
        public void ShowPopuWindow()
        {
            try
            {
                Thread _Worker = new Thread(DisplayIncommingCallPopup);
                _Worker.SetApartmentState(ApartmentState.STA);
                _Worker.Start();
                _Worker.Join();
            }
            catch (Exception ex) {MessageBox.Show(ex.Message);}
        }

        public void DisplayIncommingCallPopup()
        {
            try
            {
                CallPopupWindow callPopupWindow = new CallPopupWindow();
                callPopupWindow.ShowDialog();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }

No comments:

Post a Comment