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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:48:18+00:00 2026-06-16T02:48:18+00:00

edit: error I got is unrelated to my question. :/ -1 I starting a

  • 0

edit:
error I got is unrelated to my question. :/
-1

I starting a service on a new thread, then I want to catch an error and display a message box. because its not in the UI thread I get an error. How can I get arround this problem?

(WPF window)

Code:

xmlServiceHost = XcelsiusServiceHost.CreateXmlServiceHost(Properties.Settings.Default.XmlDataService);

serviceThread = new Thread(_ => 
{
  try { xmlServiceHost.Open(); }
  catch (AddressAccessDeniedException)
  {
    CreateRegisterDashboardServiceFile();

    //Error not in UI thread.
    //this.ShowUserInfoMessage("The dashboard service needs to be registered. Please contact support.");
  }
});

serviceThread.Start();
  • 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-16T02:48:19+00:00Added an answer on June 16, 2026 at 2:48 am

    (This answer is for WPF.)

    Well, you can open a message box from – lets say – a worker thread, but you cannot set its parent to something that belongs to the UI thread (because the worker thread would be changing the parent window by adding a new child, and the parent window does not belong to the worker thread, it normally belongs to the UI thread), so you are basically forced to leave the parent null.

    This will lead to a bunch of message boxes lying behind your application window if users don’t close them but reactivate the application window.

    What you should do is to create the message box on the UI thread with the proper parent window. For that you will need the dispatcher for the UI thread. The dispatcher will open your message box on the UI thread and you can set its proper parent.

    In situations like that I normally pass the UI dispatcher into the worker thread when I start the thread and then use a little helper class, this is particularly useful for handling exceptions on the worker thread:

     /// <summary>
    /// a messagebox that can be opened from any thread and can still be a child of the 
    /// main window or the dialog (or whatever) 
    /// </summary>
    public class ThreadIndependentMB
    {
        private readonly Dispatcher uiDisp;
        private readonly Window ownerWindow;
    
        public ThreadIndependentMB(Dispatcher UIDispatcher, Window owner)
        {
            uiDisp = UIDispatcher;
            ownerWindow = owner;
        }
    
        public MessageBoxResult Show(string msg, string caption="",
            MessageBoxButton buttons=MessageBoxButton.OK,
            MessageBoxImage image=MessageBoxImage.Information)
        {
            MessageBoxResult resmb = new MessageBoxResult();
            if (ownerWindow != null)
            uiDisp.Invoke(new Action(() =>
            {
                resmb = MessageBox.Show(ownerWindow, msg, caption, buttons, image);
    
            }));
            else
                uiDisp.Invoke(new Action(() =>
                {
                    resmb = MessageBox.Show( msg, caption, buttons, image);
    
                }));
            return resmb;
        }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a controller a error with Create/Edit ActionResult can be handled with a try-catch
edit/operacoes.php header('Content-Type: application/json'); include('../../lib/mysql.class.php'); $db = new MySQL(); if($db->Error()) $db->Kill(); //VARIÁVEIS DA FORM $id
EPiServer CMS 6 site that suddenly got this error in edit mode. Found alot
I want to customize the 'new' and 'edit' pages in rails scaffolding. Where can
redirect_to :controller=>'groups',:action=>'invite' but I got error because redirect_to send GET method I want to
EDIT: new error: Error Jquery not defined line: 208 Line 208 in this code:
[Edit] I've summarized the answer to the following below, the error lies in the
I am getting a StackOverflow Error in this code: EDIT [XmlAttribute(ID)] public string ID
I am getting an error on my browser when i try to edit or
EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question

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.