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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:45:39+00:00 2026-05-15T23:45:39+00:00

I seem to be having trouble with Threading. First let me explain how the

  • 0

I seem to be having trouble with Threading.

First let me explain how the application is built.

I have a class that extends ApplicationContext, which is my core class for the whole application, within this class I load new windows such as the login window.

Then each window talks back and forth to the application context class.

I have a method that is used to open a new message window, here it is.

public void InitiateChat(RosterItem Roster)
        {
            MessageWindow MessageWindow;
            if (WindowManager.ContainsKey(Roster.Jid.Bare) == false)
            {
                MessageWindow = new MessageWindow(Roster);
                MessageWindow.FormClosing += new FormClosingEventHandler(MessageWindow_FormClosing);

                //Store it.
                WindowManager.Add(Roster.Jid.Bare, MessageWindow);
            }
            else
            {
                MessageWindow = WindowManager[Roster.Jid.Bare];
            }

            if (MessageWindow.InvokeRequired)
            {
                MessageWindow.BeginInvoke(new InitiateChatDelegate(InitiateChat), new Object[] { Roster });
                return;
            }

            if (MessageWindow.WindowState == FormWindowState.Minimized)
            {
                MessageWindow.WindowState = FormWindowState.Normal;
            }
            MessageWindow.Show();
            MessageWindow.Activate();
        }

Now when I run the following code from an OnClick event in the main messenger window it works fine:

RosterItem RosterItem = GetSelectedContact();
if (RosterItem != null)
{
    Messenger.Bootload.MessengerApplication.Instnace.InitiateChat(RosterItem);
}

The window works perfectly, but as this is a messenger application based on XMPP and agsXMPP I have an event which is triggered by agsXMPP called OnMessage, which sends me a notification that I have an incoming message.

Here is that method.

public void ClientConnection_OnMessage(Object Sender, agsXMPP.protocol.client.Message Message) 
{
    //Load the contacts Window
    RosterItem RosterItem = ContactManager[Message.From.Bare];
    if (RosterItem != null)
    {
         InitiateChat(RosterItem);
    }
}

The problem is that when the message comes out I run the InitiateChat method but it freezes 🙁

Its the MessageWindow.Show() thats cant run fine

Can anybody help me get this to work, I’ve been trying to do it for a few days now.

  • 1 1 Answer
  • 1 View
  • 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-15T23:45:39+00:00Added an answer on May 15, 2026 at 11:45 pm

    You OnMessage event handler runs on a background thread. That’s common with socket oriented code. Lots of problems with that thread, it doesn’t run a message loop and it exits. Two reasons that make the form go catatonic.

    You’ll have to marshal the form creation method call to the UI thread. That’s normally done with Control.BeginInvoke(). A bit tricky in your case since you don’t have an obvious Form object to act as the BeginInvoke provider. You’ll have to monkey with System.Threading.SynchronizationContext.Current.Post(). I’ll leave that as an exercise, using a main window instead of a ApplicationContext would be the easier route.

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

Sidebar

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.