Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7748407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:46:39+00:00 2026-06-01T10:46:39+00:00

I am writing a Windows Store App toy application for Windows 8. It has

  • 0

I am writing a Windows Store App toy application for Windows 8.
It has just one xaml page with a TextBlock. The page has the class MyTimer as DataContext :

this.DataContext = new MyTimer();

MyTimer implements INotifyPropertyChanged and the updating of the property Time is made with a timer:

public MyTimer(){
    TimerElapsedHandler f = new TimerElapsedHandler(NotifyTimeChanged);
    TimeSpan period = new TimeSpan(0, 0, 1);
    ThreadPoolTimer.CreatePeriodicTimer(f, period);
}

with

private void NotifyTimeChanged(){
    if (this.PropertyChanged != null){
        this.PropertyChanged(this, new PropertyChangedEventArgs("Time"));
    }
}

the TextBlock has a databinding on Time

<TextBlock Text="{Binding Time}" />

When I run the application i have the following exception:

System.Runtime.InteropServices.COMException was unhandled by user code

With the message

The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))

The real problem is that I am updating the property of the class MyTimer, not the GUI itself,
I can’t figure it out, but I think the solution should use something like this one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:46:41+00:00Added an answer on June 1, 2026 at 10:46 am

    Yes, you’re notifying property changes from a thread pool thread rather than the UI thread. You need to marshal the notification back to the UI thread in the timer callback. Now, your view model is separated from your view (a good thing) therefore it doesn’t have a direct link to the Dispatcher infrastructure. So what you want to do is hand it the proper SynchronizationContext on which to communicate. To do this you need to capture the current SynchronizationContext during construction or allow it to be passed in explicitly to a constructor which is good for tests or if you’re initializing the object off the UI thread to begin with.

    The whole shebang would look something like this:

    public class MyTimer
    {
        private SynchronizationContext synchronizationContext;
    
        public MyTimer() : this(SynchronizationContext.Current)
        {
        }
    
        public MyTimer(SynchronizationContext synchronizationContext)
        {
            if(this.synchronizationContext == null)
            {
                throw new ArgumentNullException("No synchronization context was specified and no default synchronization context was found.")
            }
    
            TimerElapsedHandler f = new TimerElapsedHandler(NotifyTimeChanged);
            TimeSpan period = new TimeSpan(0, 0, 1);
            ThreadPoolTimer.CreatePeriodicTimer(f, period);
        }
    
        private void NotifyTimeChanged()
        {
            if(this.PropertyChanged != null)
            {
                this.synchronizationContext.Post(() =>
                    {
                        this.PropertyChanged(this, new PropertyChangedEventArgs("Time"));
                    });
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a .net(C#) windows application to store user passwords in it, like
I am writing Windows application (with Borland C++ Builder), which stores large number of
I am writing a Windows CE application in C# that references a native C++
I'm writing a windows service in C# that spawns multiple instances of another application
I'm writing a windows service application that needs to serialize and deserialize XML documents
I'm writing a windows forms application to be sold to small to mid-size corporations
I am writing a small .NET Windows Forms app, and I use the built-in
I´m writing a Compact Framework Application for Windows Mobile 6.5. The Application will be
i am writing an application that will need to store less than about 1mb
I'm writing a small application for Windows 7 that will track focused programs and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.