[WPF] WPF에서 Control 접근시 CrossThread 피하기


winform과 달리 invoke Require를 체크하는것이 따로 없다.
그리고 Dispatcher 로 스레드 문제를 피할수 있다.

 
using System;
using System.Windows;
using System.Windows.Threading;
using System.Threading;

namespace UFWallControler
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            //시스템타이머로 다른 스레드 생성
            System.Timers.Timer timer1 = new System.Timers.Timer(1000);
            timer1.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed1);
            timer1.Start();

            //wpf 타이머로 같은 스레드에서 실행 
            DispatcherTimer t = new DispatcherTimer();
            t.Interval = new TimeSpan(0, 0, 1);
            t.Tick += new EventHandler(t_Tick);
            t.Start();
        }

        void t_Tick(object sender, EventArgs e)
        {
            SafeThreadTextBox("timer call");
        }

        void timer_Elapsed1(object sender, System.Timers.ElapsedEventArgs e)
        {
            SafeThreadTextBox("timer call");
        }

        void SafeThreadTextBox(string s)
        {
            //
            //만약 서로의 스레드가 같다면
            //winform의 invokeRequre테스트
            //
            if (Thread.CurrentThread == textBox1.Dispatcher.Thread)
            {
                textBox1.Text += "inThread " + s + Environment.NewLine;
            }
            else
            {
                textBox1.Dispatcher.BeginInvoke(
                    new Action(() => textBox1.Text += "outThread " + s + Environment.NewLine 
                ));
            }
        }
    }
}
Yamecoder 야매코더_
C# 2011. 2. 21. 23:47

댓글을 달아 주세요

  1. 이전 댓글 더보기
  2. BlogIcon botanical slimming 2014.11.10 06:58  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  3. BlogIcon woolrich Sito ufficiale 2014.11.11 01:56  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  4. BlogIcon mont blanc starwalker 2014.11.11 01:57  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  5. BlogIcon moncler collezione inverno 2010 uomo 2014.11.12 11:44  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  6. BlogIcon moncler trebaseleghe prezzi 2014.11.12 11:46  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  7. BlogIcon copy Sunglasses wholesale 2014.11.17 09:04  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  8. BlogIcon montblanc meisterstuck 2014.11.20 03:29  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  9. BlogIcon Ralph Lauren tilbud 2014.11.23 08:08  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  10. 匿名 2014.12.03 05:44  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  11. BlogIcon 轻质复合墙板机 2015.01.02 19:47  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  12. 匿名 2015.01.07 17:45  수정/삭제  댓글쓰기

    이용약관위배로 관리자 삭제된 댓글입니다.

  13. 匿名 2015.02.11 14:03  수정/삭제  댓글쓰기

    을데骑士服务端天上碑服务端美丽世界服务端科洛斯服务端石器时代服务端

    完美世界服务端烈焰服务端洛汗服务端新魔界服务端绝对女神私服务端

    征服服务端传说45服务端天之炼狱服务端天堂II私服务端墨香私服务端


    传奇开sf一条龙开区服务-

    天龙八部开私服一条龙服务-


    传奇广告代理-

    IDC服务器以及空间租用-

    魔域私服开区一条龙服务-


    客服咨询QQ(企鹅扣扣)49333685

    Email:49333685@qq.com

    后浪科技更多商业版本免费开放下载




    后浪科技科技仿官神武血魔版服务端



    后浪科技石器时代VIP最新V10纯金开区端



    后浪科技热血江湖3.5宠门武勋开区端



    后浪科技剑侠情缘X2.0商业版本服务端



    后浪科技v2.07已开5区七转神台天降横财八卦玄阵血魄技들지

  14. 匿名 2015.03.01 14:22  수정/삭제  댓글쓰기

    료련大话西游服务端凡人修真服务端大话西游服务端页游服务端问道服务端

    跑跑卡丁车服务端英雄远征服务端幻灵游侠私服务端洪荒神话私服务端

    完美世界服务端烈焰服务端洛汗服务端新魔界服务端绝对女神私服务端


    魔兽私服开区一条龙服务-

    传奇私服开传奇一条龙服务-


    传奇广告代理-

    IDC服务器以及空间租用-

    魔域开区sf一条龙开区服务-


    客服咨询QQ(企鹅扣扣)1325876192

    Email:1325876192@qq.com

    商业版本免费开放下载




    紫川科技最新毁灭天下1.85狂雷独家合击热血复古三职业新装传奇服务端



    紫川科技20星大极品良装+80麒麟锻造中变传奇服务端



    紫川科技独家轻变1.89奥妙转生神龙锻造珍珑元素版传奇服务端



    紫川科技独家九转1.85四皇冠加倍装备特戒龙卫리이

  15. BlogIcon burberry femme 2015.03.27 21:10  수정/삭제  댓글쓰기

    고그a été signé vetement burberry le 19 mai de la marine l'ennemi commun de l'Accord militaire; le contenu principal: la Chine appuie le Japon. dont beaucoup sont des bordels dans les cordes,La pompe à la Chine, c'est loin derrière. par rapport à la richesse Yi 劻,de Chine il y a un nom de Wang Guan de deuxième génération, si votre majest&e일지

  16. BlogIcon sac burberry pas cher 2015.03.31 00:03  수정/삭제  댓글쓰기

    에이Avant de tirer la carte bancaire bénéficiaire oublier les hommes et 7 000 yuan par le Ministère public - sohu News

    Source: Sohu.com mise à jour: 2015-03-30 02: 29: 23 Classification: les mots - clés: le retrait de | devant | retraits oublier le carte bancaire et 7000 hommes sont le Ministère public - sohu nouvelle devant retraits oublier le carte bancai리그

  17. 匿名 2015.03.31 08:50  수정/삭제  댓글쓰기

    서하After browsing around the site for a while you will notice that they have everything under the sun. That is great because there is a huge variety of things that you can choose from it really does not matter what you want,How the Pros Shop For Bargain. When I shop around my areas and town or city and I know that they do not have the product I want there is one place I can go to that will most likel상데

  18. 匿名 2015.04.01 06:28  수정/삭제  댓글쓰기

    상네Lacoste boots and a beret big mesh, or even the entire pleated skirt, tights and wool biker boots. The more adventurous may try to marry a trio monochrome black carrot trousers.



    Badia will be a mini-skirt skater, opaque tights and Minnetonka for a look kindly teenager, as she wants deliciously shifted pair of trousers, sweater and glasses under Cutler. Olympia for its partner with a slim we없비

  19. 匿名 2015.04.03 13:49  수정/삭제  댓글쓰기

    있분火车采集器html简单模板示范






    Honda - Lord of the Rings







    [标签:来源]








    I wonder if Soichiro Honda knew what he was starting when as a schoolboy in the late thirties, he began his development of the piston ring. As his ideas came to fruition and production began, he tried to sell his rings to Toyota, but was told that his work didn't meet their rigorous standards. Undaunted,마마

  20. 匿名 2015.04.03 17:37  수정/삭제  댓글쓰기

    기는But in contrast, Yamaha scooters are very economical. On the low end you could spend as little as $2000 dollars for a brand new Yamaha scooter. But on the high end you could spend as much as $8000 to $9000 dollars. The higher end models have more bells and whistles. They also have larger engines allowing them to be very good resources in urban cities.



    Through the years Yamaha has worked to 겠리

  21. 匿名 2015.04.06 01:07  수정/삭제  댓글쓰기

    리이presents the visible face of cloud computing that most people have already experienced. The advantages of web-based applications such as Gmail, Twitter,Why You Should Learn To Devel, and Facebook are pretty obvious - there's nothing to download to your PC, you can access them from anywhere, they're constantly being enhanced and every time updates are made they become instantly available to any use비어

Powerd by Tistory, designed by criuce
rss