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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:14:19+00:00 2026-05-15T11:14:19+00:00

I’m trying to invoke a dialog on the UI dispatcher : class DialogService :

  • 0

I’m trying to invoke a dialog on the UI dispatcher :

class DialogService : IDialogService
{
    private readonly Dispatcher _dispatcher = Application.Current.Dispatcher;

    public bool? Show(IDialogViewModel viewModel)
    {
        if (_dispatcher.CheckAccess())
        {
            var dialogWindow = new DialogWindow();
            return dialogWindow.Show(viewModel);
        }
        else
        {
            Func<IDialogViewModel, bool?> func = Show;
            return (bool?)_dispatcher.Invoke(func, viewModel);
        }
    }
}

However, the call to Invoke blocks forever, and Show is never called on the UI thread…

Using BeginInvoke is not an option : I need the result immediately, because I’m handling an event from a remote object (using .NET remoting)

Any idea ?


UPDATE

Here is a more complete description of the problem :

I have an client application that communicates with a Windows service using .NET Remoting. At some point, the client makes a call to the service to perform an operation (this call is triggered by a user action, a click on a button in that case). The service might need credentials to perform the operation: in that case, it raises a CredentialsNeeded event, handled by the client. The client then shows a dialog to prompt the user for credentials, and sets the appropriate properties in the event’s arguments. When the event handler returns, the service uses the credentials to complete the operation, and returns control to the client.

So, when I receive the event, the UI thread is waiting for an operation to complete on the service side… I assume it’s the reason why the Invoke call is not processed, but how can I work around it ? Can I create another UI thread to show the dialog ? In WinForms, I know I could start another message pump with Application.Run, but I don’t know how to do the same in WPF…

  • 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-15T11:14:20+00:00Added an answer on May 15, 2026 at 11:14 am

    I eventually found a solution to my problem : I just need to show the dialog on a new thread, with its own dispatcher. Here’s the modified code :

    class DialogService : IDialogService
    {
        private readonly Dispatcher _dispatcher = Application.Current.Dispatcher;
    
        public bool? Show(IDialogViewModel viewModel)
        {
            if (_dispatcher.CheckAccess())
            {
                DoShow(viewModel);
            }
            else
            {
                bool? r = null;
                Thread thread = new Thread(() => r = DoShow(viewModel));
                thread.SetApartmentState(ApartmentState.STA);
                thread.Start();
                thread.Join();
                return r;
            }
        }
    
        private static bool? DoShow(IDialogViewModel viewModel)
        {
            var dialogWindow = new DialogWindow();
            return dialogWindow.Show(viewModel);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.