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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:59:09+00:00 2026-05-24T05:59:09+00:00

Right, I am programming something for a GUI at this moment. I am however

  • 0

Right, I am programming something for a GUI at this moment. I am however facing a synchronization problem that I can’t seem to fix myself.

I am starting/stopping the playback of a video remotely through UDP. The incoming code/command is parsed and then executed in the ‘Window’ class.

Since it is a GUI element any calls going to an element has to be executed on the thread that it was created from. Though, my UDP client is run on its own thread. Thus any calls need to go through the Dispatcher.Invoke method.

That is working fine, however. There are multiple problems with this. For example the ‘load’ method and ‘play’ method can be executed directly after each other. Which can cause the ‘play’ method to be executed before the ‘load’ method. Because I can’t control when an action is invoked on said object.

So I thought, I’ll use a monitor/mutex/semaphore/lock() on the object and then wait before it is released a again. See below code snippets. But this is causing an exception:

SynchronizationLockException is thrown by calling the Exit, Pulse,
PulseAll, and Wait methods of the Monitor class from an unsynchronized
block of code.

So I am looking for a better/working way to synchronize both threads. That if the call is invoked through the dispatcher, the other thread will basicly wait until the invoked method is done invoking.

Also, excuse my wording if I am using wrong terms.

Dispatch method:

#region ExecuteDispatch Members
public void Dispatch(Callback call)
{
    Dispatch(this, call);
}
public void Dispatch(DispatcherObject o, Callback call)
{
    if (!o.Dispatcher.CheckAccess())
    {
        o.Dispatcher.Invoke(
            System.Windows.Threading.DispatcherPriority.Send,
            new Action(call)
        );
    }
    else
    {
        call();
    }
}
#endregion

Method that should be ‘synchronized’:

Monitor.Enter(player);
Dispatch(delegate()
{
    player.Stop();
    Monitor.Exit(player);
});
Monitor.Enter(player);
Monitor.Exit(player);
  • 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-05-24T05:59:10+00:00Added an answer on May 24, 2026 at 5:59 am

    One possible way is to have one thread signal the other that he finished his work. Therefore you can use the AutoResetEvent or the ManualResetEvent:

    AutoResetEvent evt = new AutoResetEvent(false);
    
    Dispatch(delegate()
    {
        player.Stop();
        evt.Set();
    });
    
    evt.WaitOne(); //Here the thread waits until Set is called on evt
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It seems this problem is quite popular on programming. I have a table that
Something I don't enjoy about programming is learning a new API. For example, right
Something that happens to me a lot while web programming: I want to run
I am I think ok at algorithmic programming, if that is the right term?
This is been making my programming really frustrating lately. I´m in Argentina right now
I can't post any code right now, since the computer I'm programming on has
I hope this is the right place to post this and somebody can help.
For a problem that I'm working on right now, I would like a reasonably
Right now, I'm programming the networking for my online game, and I'm not really
When programming in Eclipse I use small vertical bar on the right side of

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.