Create a multi threaded web browsing application. : Thread « Windows Presentation Foundation « C# / C Sharp






Create a multi threaded web browsing application.

  

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MultiBrowse" Height="600" Width="800" Loaded="OnLoaded">
  <StackPanel Name="Stack" Orientation="Vertical">
    <StackPanel Orientation="Horizontal">
      <Button Content="New Window" Click="NewWindowHandler" />
      <TextBox Name="newLocation" Width="500" />
      <Button Content="GO!" Click="Browse" />
    </StackPanel>
    <Frame Name="placeHolder" Width="800" Height="550"></Frame>
  </StackPanel>
</Window>
//File:Window.xaml.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Threading;
using System.Threading;

namespace WpfApplication1
{
    public partial class Window1 : Window
    {
        public Window1() : base()
        {
            InitializeComponent();
        }

        private void OnLoaded(object sender, RoutedEventArgs e)
        {
           placeHolder.Source = new Uri("http://www.java2s.com");
        }

        private void Browse(object sender, RoutedEventArgs e)
        {
            placeHolder.Source = new Uri(newLocation.Text);
        }
        private void NewWindowHandler(object sender, RoutedEventArgs e)
        {       
            Thread newWindowThread = new Thread(new ThreadStart(ThreadStartingPoint));
            newWindowThread.SetApartmentState(ApartmentState.STA);
            newWindowThread.IsBackground = true;
            newWindowThread.Start();
        }
        private void ThreadStartingPoint()
        {
            Window1 tempWindow = new Window1();
            tempWindow.Show();       
            System.Windows.Threading.Dispatcher.Run();
        }
    }
}

   
    
  








Related examples in the same category

1.WPF ThreadingWPF Threading
2.Thread Sleep in Button Click handlerThread Sleep in Button Click handler
3.Check Whether You Are Running on the UI ThreadCheck Whether You Are Running on the UI Thread
4.Ensure That You Are Running on the UI ThreadEnsure That You Are Running on the UI Thread
5.Execute a Method Asynchronously Using the Dispatcher QueueExecute a Method Asynchronously Using the Dispatcher Queue
6.ThreadPool.QueueUserWorkItemThreadPool.QueueUserWorkItem
7.BlockThread.xamlBlockThread.xaml
8.Keep the UI from becoming non-responsive in single threaded application which performs a long operation.Keep the UI from becoming non-responsive in single threaded application which performs a long operation.