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

  • SEARCH
  • Home
  • 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 8393609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:50:20+00:00 2026-06-09T19:50:20+00:00

I have not used wpf alot and thought it would be a simple proccess

  • 0

I have not used wpf alot and thought it would be a simple proccess to change the colour of an ellipse at runtime. I have a FileWatcher and in the event created I want to change the colour of the ellipse to a colour and back again, creating a blinking effect. (created is the ellipse, br4 is a solid colour brush defined in xaml)

    public void watcherCreated(object seneder, FileSystemEventArgs e)
    {

        Application.Current.Resources["br4"] = new SolidColorBrush(Colors.Green);
        created.Fill = (SolidColorBrush)Application.Current.Resources["br4"];

    }

as soon as a file is created in the path which fires the event i get this error: Invalid operation exception
The calling thread cannot access this object because a different thread owns it.
I have looked for a solution with the freeze() method, but with no success.

     created.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(
            delegate()
            {
                Application.Current.Resources["br4"] = new SolidColorBrush(Colors.Green);
                created.Fill = (SolidColorBrush)Application.Current.Resources["br4"];
            }
        ));

got it thanks for comments

  • 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-09T19:50:22+00:00Added an answer on June 9, 2026 at 7:50 pm

    You can only access UI elements from the same thread in which they were created.

    You should use Dispatcher.Invoke or Dispatcher.BeginInvoke to have a delegate called on the UI thread…where you can then access the “created” elements’ “Fill” property.

    See this link for an explanation of the problem:

    • http://www.switchonthecode.com/tutorials/working-with-the-wpf-dispatcher

    Instead of trying to set the changing colour in the UI…what you can do is expose a property on your ViewModel which holds a state.

    When your FileWatcher notifies you of a newly created file (by calling your watcherCreated method) you just set that state in your ViewModel.

    In your UI…use a Binding with a Converter to bind to the state property in your ViewModel. The converter will determine what Brush to use depending on the state e.g. if state is 1 return a Green brush, if state is 0 return a Red brush.

    To reset the state back to the “off” position…you could have a timer that after say 1 second, etc…sets the state value back to off.

    By doing this….you separate the state from the UI.

    If in the future you wanted a more sophisticated way of showing the state in the UI…e.g. having an animation (using StoryBoards/Visual State Manager) that gradually fades away from Green back to Red…then you could have that animation triggered, once again based on the state in the ViewModel.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have not used jquery much yet and not very familiar with it. Trying
I have not used many lambda expressions before and I ran into a case
I have not used Twitter enough to become familiar with its terminology or the
I have not used valgrind before, but I need to use it to check
I have not used ASP.NET Membership and Role Providers before but looking for a
Disclaimer: I have not used RoR, and I have not generated tests. But, I
I have integrate draw line in my application i have not used OpenGL or
I'm working on a security project in Javascript (something I honestly have not used),
How to make the forms non scrollable in sencha touch? I have not used
I know system.exit(0) should not be used. I have read plenty of tutorials as

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.