posts - 280, comments - 321, trackbacks - 0

My Links

News

View Steve Michelotti's profile on LinkedIn

Twitter












Tag Cloud

Archives

Post Categories

Blend Bloggers

Bloggers that I follow

Books

F# Bloggers

F# Communities

F# Online Books

Fonts

HTML CSS ASP

Machine Learning

My Links

My Local UserGroups

My Online Presence

MY SA Links

Online Seminars

SA Software Companies

Web Design

Accessing the Dispatcher Thread from your ViewModel

 

A little snippet that might help anyone using the MVVM pattern. If we want to marshal something through to the Dispatcher Thread from a view model we can do the following  within the ViewModel class…

 

        private void SendingToTheDispatcherThread()
        {
            Dispatcher dispatcher = Application.Current.Dispatcher;


            if (!dispatcher.CheckAccess())
            {
                dispatcher.BeginInvoke((Action)(() =>
                                                    {
                                                        // put code for the dispatched here
                                                    }));
            }
            else
            {
                // put code for the dispatched here
            }
        }

Print | posted on Wednesday, October 12, 2011 8:57 AM | Filed Under [ C# ]

Feedback

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: