■ AppDomain 클래스 : 동일 프로세스에서 멀티 WPF 애플리케이션 실행하기

------------------------------------------------------------------------------------------------------------------------

 


TestProject.zip


MainWindow.xaml

 

 

<Window x:Class="TestProject.MainWindow"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Width="400"

    Height="300"

    Title="AppDomain 클래스 : 동일 프로세스에서 멀티 WPF 애플리케이션 실행하기"

    FontFamily="나눔고딕코딩"

    FontSize="16">

    <Grid>

        <ContentControl

            HorizontalAlignment="Center"

            VerticalAlignment="Center"

            Content="{Binding DomainName}" />

    </Grid>

</Window>

 

 

MainWindow.xaml.cs

 

 

using System;

using System.Windows;

 

namespace TestProject

{

    /// <summary>

    /// 메인 윈도우

    /// </summary>

    public partial class MainWindow : Window

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - MainWindow()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainWindow()

        {

            InitializeComponent();

 

            DataContext = new { DomainName = AppDomain.CurrentDomain.FriendlyName };

        }

 

        #endregion

    }

}

 

 

Program.cs

 

 

using System;

using System.Threading;

using System.Windows;

 

namespace TestProject

{

    /// <summary>

    /// 프로그램

    /// </summary>

    class Program

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Static

        //////////////////////////////////////////////////////////////////////////////// Private

 

        #region 프로그램 시작하기 - Main()

 

        /// <summary>

        /// 프로그램 시작하기

        /// </summary>

        [STAThread()]

        [LoaderOptimization(LoaderOptimization.MultiDomainHost)]  

        private static void Main()

        {

            AppDomain appDomain1 = AppDomain.CreateDomain("첫번째 전용 도메인");  

            AppDomain appDoamin2 = AppDomain.CreateDomain("두번째 전용 도메인");  

 

            CrossAppDomainDelegate action = () => {

 

                Thread thread = new Thread

                (

                    () => {

 

                        Application application = new Application();

 

                        application.MainWindow = new MainWindow();

 

                        application.MainWindow.Show();

 

                        application.Run();

                    }

                );

 

                thread.SetApartmentState(ApartmentState.STA);  

 

                thread.Start();  

            };

 

            appDomain1.DoCallBack(action);

            appDoamin2.DoCallBack(action);

        }

 

        #endregion

    }

}

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요