Home Ask Login Register

Developers Planet

Your answer is one click away!

PblicHieip Hag Ana February 2016

activating a custom new window while debuging in visual studio

in code below I show information on my application , if there is something that was not set (...in one of the classes or methods) correctly a window pops up with the current message telling what was missing .

there is only one problem I wonder if and how could this be done, the application is frozen while still debugging so I can not move the window or click on it's control,

is there any workaround you think of I could apply ?

void SomeMainThreadMethod()
    new System.Threading.Thread(() => ProcessSomeLongRunningTask()).Start();
//then from another helper class
void ProcessSomeLongRunningTask()
    Application.Current.Dispatcher.Invoke(new Action(() =>CustomW.MsgBoxShow(" Title ", "Msg")), System.Windows.Threading.DispatcherPriority.Normal);


Digitalsa1nt March 2016

The issue here is that you're processing your message box on your main dispatcher thread and as you know this defaults as a dialog box and steals focus from the main application window.

So you could try executing the message box in the new thread you create or you could create your own custom user control with the same features as the message box but it won't inherit that tools behavior.

You can still run it from a secondary thread like you created, but remember to wrap anything that interacts with objects made by the main dispatcher as a delegate action

       public void LongProcess()
            Thread t = new Thread(new ThreadStart(

                //Complex code goes here

               this.Dispatcher.Invoke((Action)(() =>

                  //Any requests for controls or variables that you need
                  //from the main application running on the main dispatcher
                  //goes here


                //Finally once you've got the information to return to
                //your user call a message box here and populate the 
                //message accordingly.

                MessageBox.Show("", "");

                //If a message box fails or isn't good enough
                //create your own user control and call it here like:

                usrConMessage msg = new usrConMessage();
                msg.strTitle = "Whatever";
                msg.strContent = "Whatever";
                msg.show(); //Not a dialog so doesn't steal focus

                //That is normally how I would go about providing a
                //unique and polished user experience.


Post Status

Asked in February 2016
Viewed 3,454 times
Voted 9
Answered 1 times


Leave an answer

Quote of the day: live life