What should you do to ensure that the following requirements are met?

You are creating a Windows Presentation Foundation application by using Microsoft .NET Framework 3.5.
The application defines a BrowserWindow class. Each instance of the BrowserWindow class allows the user to browse a Web site in a separate window.
When a new browser window is opened, the user is redirected to a predefined URL.
You write the following code segment.

01 private void OpenNewWindow(object sender, RoutedEventArgs e)
02 {
03 Thread newWindowThread = new Thread(new ThreadStart(NewThreadProc));
04
05 newWindowThread.Start();
06 }
07 private void NewThreadProc()
08 {
09
10 }

You need to ensure that the following requirements are met:
* The main window of the application is not blocked when an additional browser window is created.
* The application completes execution when the main window of the application is closed.
What should you do?

You are creating a Windows Presentation Foundation application by using Microsoft .NET Framework 3.5.
The application defines a BrowserWindow class. Each instance of the BrowserWindow class allows the user to browse a Web site in a separate window.
When a new browser window is opened, the user is redirected to a predefined URL.
You write the following code segment.

01 private void OpenNewWindow(object sender, RoutedEventArgs e)
02 {
03 Thread newWindowThread = new Thread(new ThreadStart(NewThreadProc));
04
05 newWindowThread.Start();
06 }
07 private void NewThreadProc()
08 {
09
10 }

You need to ensure that the following requirements are met:
* The main window of the application is not blocked when an additional browser window is created.
* The application completes execution when the main window of the application is closed.
What should you do?

A.
Insert the following code segment at line 04.
newWindowThread.SetApartmentState(ApartmentState.STA);
newWindowThread.IsBackground = true;
Insert the following code segment at line 09.
BrowserWindow newWindow = new BrowserWindow();
newWindow.Show();
Application app = new Application();
app.Run(newWindow);

B.
Insert the following code segment at line 04.
newWindowThread.IsBackground = true;
Insert the following code segment at line 09.
newWindowThread.SetApartmentState(ApartmentState.STA);
BrowserWindow newWindow = new BrowserWindow();
newWindow.Show();
Application app = new Application();
app.Run(newWindow);

C.
Insert the following code segment at line 04.
newWindowThread.SetApartmentState(ApartmentState.STA);
newWindowThread.IsBackground = false;
Insert the following code segment at line 09.
BrowserWindow newWindow = new BrowserWindow();
System.Windows.Threading.Dispatcher.Run();
newWindow.Show();

D.
Insert the following code segment at line 04.
newWindowThread.SetApartmentState(ApartmentState.STA);
newWindowThread.IsBackground = true;
Insert the following code segment at line 09.
BrowserWindow newWindow = new BrowserWindow();
newWindow.Show();
System.Windows.Threading.Dispatcher.Run();



Leave a Reply 0

Your email address will not be published. Required fields are marked *