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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:01:30+00:00 2026-05-27T16:01:30+00:00

I’m writing a game that uses WPF for its interface, and Direct3D11 for rendering

  • 0

I’m writing a game that uses WPF for its interface, and Direct3D11 for rendering the world. The rendering happens on its own thread but it needs to make use of a D3DImage in the window, so I need to use a SynchronizationContext to switch to the UI thread when rendering. When the game first starts up I make a DispatcherSynchronizationContext from the Application.Current.Dispatcher. Some time after this happens, a window is created and then is stored in Application.Current.MainWindow. When its time to render I have to switch to the context like so:

async {
    ...
    do! Async.SwitchToContext state.Context
    //render stuff

}

Everything is fine up until the main window closes. Once that happens my handler for Application.Exit runs, which tells all subsystems to shut down and then waits for their responses. The problem is the render thread hangs either on the next Async.SwitchToContext, or if the switch already happened just before the window closed then it hangs sometime during the actual rendering, so it can never respond to the shutdown request.

The DispatcherSynchronizationContext doesn’t become null, and both the value of DSC’s HasShutdownStarted and HasShutdownFinished are false. I’m not getting any exception either. The application is still running, it won’t exit until it gets a response from all the subsystems.

What is happening at this point in the program? The application is still running, so its dispatcher should still be there, so I should still be able to switch to its context. There is no change in the SynchronizationContext before and after the window closes that would lead me to believe its no longer valid, so I have no idea how to check if its safe to switch or not.

  • 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-27T16:01:30+00:00Added an answer on May 27, 2026 at 4:01 pm

    (Reposting from comments)

    For your value of Application.Current.ShutdownMode, the behavior you’re seeing is expected — because you have no other window open other than your main window, when your main window is closed, (quoting the docs)

    Windows Presentation Foundation (WPF) implicitly calls Shutdown when the last window in an application closes.

    And of course, invoking Shutdown (directly or indirectly) explicitly terminates the process.

    If you want your process to remain alive even after all windows are closed, you must assign the value ShutdownMode.OnExplicitShutdown to Application.Current.ShutdownMode:

    The lifetime of some applications may not be dependent on when the main window or last window is closed, or may not be dependent on windows at all. For these scenarios you need to set the ShutdownMode property to OnExplicitShutdown, which requires an explicit Shutdown method call to stop the application. Otherwise, the application continues running in the background.

    Sounds like your exact scenario to me. ;-]

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I need to clean up various Word 'smart' characters in user input, including but
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I

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.