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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:36:27+00:00 2026-05-24T04:36:27+00:00

I have a weird deadlock situation. After attached visual studio. I saw 3 threads

  • 0

I have a weird deadlock situation. After attached visual studio. I saw 3 threads that stuck.

  1. Thread 1:

    if (SomeEvent != null)
       SomeEvent(this, new SomeArg) --> Stuck
    
  2. Thread 2:

    if (SomeEvent2 != null)
        SomeEvent2(this, new SomeArg2) --> Stuck
    
  3. Main Thread:

    public object (Delegate method, object[] args)
    {
       ...
       SynchronizationContext.Send(delegate(object state))
       {
           ...
           method.DynamicInvoke(args); --> Stuck
       }
    }
    

These three threads are stuck, and when I check their call stacks, I wasn’t able to find any shared resource, like lock(), or Monitor.Wait(). I believe they all stuck on external calls.

In addition, I can’t tell what method.DynamicInvoke(args) is doing and what this method supposed to be.

The only one thing I found is that the attached event handlers may cause deadlock. However, since VS has show me this is where it stucks, and not at the event handler code. I think it may be something else.

In term of the application, I know this is a race condition, because the application was trying to perform loading and unload data around the same time, so this problem is rather hard to reproduce.

My question are:

  1. Why would .NET thread hangs when raising an event, is it even possible?
  2. Does the Main UI thread need to be used when raising an event?
  3. If indeed it is possible for the event raising to deadlock, how should I prevent this?

Thanks

  • 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-24T04:36:28+00:00Added an answer on May 24, 2026 at 4:36 am
    1. Is it possible for a thread to hang when raising an event? Yes, it is. The thread of execution doesn’t return from the raising of the event until the event handlers are finished. Event handlers could be anything, and therefore they can hang. If an event handler hangs, the event-raising thread hangs.

    2. No, the Main UI thread does not need to be used to raise events. Any thread can raise events.

    3. Event raising isn’t especially prone to deadlocks, but it isn’t immune to it either. When you raise an event the thread you are on executes whatever code has been registered as event handlers. That code isn’t special. It’s just code executing on the same thread that raised the event. It can deadlock or not for all the same reasons any code can deadlock.

    The point is that there isn’t anything particularly magical about how the code for events and event handlers gets executed. While I’m simplifying to the point that I’m almost certainly wrong, the basics are that events are just multicast delegates that are available to have elements added to and removed from their invocation list publicly, but all other forms access are private. There is nothing about events that is thread related. Using events wouldn’t impact the existence of a deadlock as compared to executing the same code in the event handlers some other way.

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

Sidebar

Related Questions

have a weird situation. I'm using Glassfish server for my Enterprise application. In that
I have a weird date rounding problem that hopefully someone can solve. My client
I have a weird issue that only seems to be affecting IE 7. The
I have a weird problem with images in visual web developer, I cant change
I have some extremely weird behavior that seems to result in silent exceptions. How
I have found weird behavior of CUDA. After I got segfault in my kernel,
I have a weird problem with Magento cache. I have an extension that have
I have a weird XML file that I'm trying to parse. <Data> <Row> <Field
Greetings SO, I have a weird problem that I don't seem to be able
I have a weird error in my C++ classes at the moment. I have

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.