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 7714377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:06:43+00:00 2026-06-01T02:06:43+00:00

I have two different projects and in one, I have a class that defines

  • 0

I have two different projects and in one, I have a class that defines a custom event to fire under certain conditions:

  public delegate void ButtonHandler(object myObject,
                                           GuitarArgs myargs);

        public event ButtonHandler OnButtonPress;

... other stuff ...

  GuitarArgs myArgs = new GuitarArgs( guitarState );
                if(OnButtonPress!= null)
                     OnButtonPress(this, myArgs);

Then in another project I create an instance of this class and subscribe to this event:

Guitar.OnButtonPress += Guitar_OnButtonPress;

The event then fires properly, but it seems to be on a different thread, because when I try to access some UI elements, I get an error : The calling thread cannot access this object because a different thread owns it.

The code throwing the error is:

 void Guitar_OnButtonPress(object myObject, Guitar.GuitarArgs myargs)
        {
            GuitarCheck(myargs.State);
        }

        private void GuitarCheck(GuitarState getState)
        {
                if (getState.green) 
                {
                    VisualTreeHelper.HitTest(guitarCanvas, null,
                                             MyHitTestResult,
                                             new GeometryHitTestParameters(
                                                 new RectangleGeometry(new Rect(1, 411, 88, 78))));
                }
}

What can I do to make this run?

Thank you.

  • 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-01T02:06:44+00:00Added an answer on June 1, 2026 at 2:06 am

    If you are using WinForms
    this.Invoke(() => GuitarCheck(myargs.State));
    (http://msdn.microsoft.com/en-us/library/zyzhdc6b.aspx)

    If you are using WPF
    this.Dispatcher.Invoke(() => GuitarCheck(myargs.State));
    (http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.invoke.aspx)

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

Sidebar

Related Questions

In my system I have two different projects, one defining its interfaces and another
I have here two applications in two different projects in eclipse. One application (A)
Resource dictionary 03-11-2010 10:56 AM | I have two different projects. I linked a
I have two different .Net projects, hosted on github. I would like to create
I have a project where I have to interact with two different devices that
I'm using eclipse, and I have two android projects which have different topics. And
OK, so I have two (completely unrelated, different project) classes using iterators now. One
I have two frameworks in my Xcode project that both define a class with
I have two classes defined as such: public class Questionnaire { public int QuestionnaireID
In one of my projects, I have two data transfer objects RecordType1 and RecordType2

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.