In the code below, I call method that opens a custom new window. However when application is doing some long running task I wish to still be able to activate the window. Is it possible to do it on another thread or by using the Task class?
public static class CustomW { static Custom_Window_Chrome_Demo.ThemedWindow MsgBox(string Msgbx_TTL, string Msgbx_Contnt) { var w_mbx = new Custom_Window_Chrome_Demo.ThemedWindow(); w_mbx.Width = 950; w_mbx.Height = 159; w_mbx.Title = Msgbx_TTL; Grid g = new Grid(); StackPanel spM = new StackPanel(); TextBlock TblckErrMsg = new TextBlock(); //more settings...... } } This is how I tried to invoke it,
public void newMsgBoxShow(string Msgbx_TTL, string Msgbx_Contnt) { System.Threading.Thread s = new System.Threading.Thread( ()=> CustomW.MsgBox(Msgbx_TTL, Msgbx_Contnt).Show() ); } but when I am using the new thread I am getting the following error.
The calling thread must be STA, because many UI components require this
What is the correct way to achieve the required result ?
CustomW.MsgBox())from the new thread same results