I have a WPF application with one window. This window has one image and one textblock. The application takes in a command line argument that is the name of an ISO to mount. It then changes screen res if needed, loads the application on the virtual cd and waits for that process to terminate. After it has the ISO is unmounted and the screen res put back to the original state. While all this is going on a message is displayed to the user to tell them where in the process they are.
I am using the textblock to display the progress text to the user and the whole process kicks off on the following event.
private void Window_ContentRendered(object sender, EventArgs e)
{
txtMessage.Text = ConfigurationManager.AppSettings.Get("MountISO");
//Call routine to mount ISO
txtMessage.Text = ConfigurationManager.AppSettings.Get("SettingResolution");
// call routine to set resolution
.
.
.
.etc
}
However the window loads as expected but no text displays in the textblock.
I did have the code in the Window_Loaded event but the window remained minimised until the processing had finished.
I’m obviously going about this the wrong way but cannot find anything to tell me where I am going wrong.
Asynchronous programming may be what you want to do here. Search StackOverflow for things like
Taskin C# or read the Microsoft documentation on the Task class.The
ContentRenderedevent is not the place to put things like that. Usually it would beWindow_Loadedas you did in the first place, but of course the application is blocked by the long lasting actions you’re performing.