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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:33:54+00:00 2026-05-30T20:33:54+00:00

I am trying to build a simple LAN chat in c# using WPF as

  • 0

I am trying to build a simple LAN chat in c# using WPF as a GUI. Since I want to enable server-less chatting, I’d like for each instance of the application to listen at an IP for multicasted messages and send multicasts to that IP as well. However, all the various tutorials for threaded networking I find on the net use the console, not WPF, which is set in its own thread. I have tried adapting those tutorials, but there is always something failing, such as the GUI thread suspending, or the messages not being processed/added to the GUI. Tutorials about consumer/producer threading systems would be great as well.

  • 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-30T20:33:55+00:00Added an answer on May 30, 2026 at 8:33 pm

    There’s nothing different between your scenario and any other scenario with interthread communication except that you’ve got a lot of free work that you can take advantage of b/c you’re marshalling between between WPF and some other thread.

    Short version:
    When you receive a message from another client in your local stack and you need to let WPF know, use Dispatcher.Invoke from the networking thread to marshal a call to the WPF thread, presumably passing it some kind of Message object. This is extra easy with lambdas:

    First, store a reference to the WPF dispatcher on your background thread during app initialization. This is easy because (assuming you aren’t pathologically multithreaded) your WPF thread is the one that’s spinning up your network thread:

    var guiDispatcher = Dispatcher.CurrentDispatcher;
    

    Once your other thread is able to access the gui dispatcher, it can asynchronously run code on that dispatcher’s context (in our case, the WPF GUI thread):

    Message msg = myNetworkComms.GetMessage(); // or whatever
    Action updateGui = () => myViewModel.ApplyNewMessage(msg);
    guiDispatcher.BeginInvoke(DispatcherPriority.Normal, updateGui); // Run updateGui on GUI thread
    

    All that said, why are you spinning up a separate thread for your network I/O? It seems awfully wasteful of resources. Are you sure there aren’t any async network I/O methods you can take advantage of?

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

Sidebar

Related Questions

I'm trying to build a simple HTTP Server using Java, using java.net.ServerSocket = new
Hey, so I'm trying to build a simple lan game using sockets (not tcpclient
I'm trying to build a simple parser, and since InputStream doesn't have some peek-like
I am trying to build a simple nested html menu using HAML and am
Im trying to build a simple, lightweight product viewer using jquery. I have a
I'm trying to build a simple multithreaded tcp server. The client connects and sends
I am trying to build a simple search-engine using HtmlAgilityPack and Xpath with C#
I'm trying to build a simple application, with the finished program looking like this
I'm trying to build a simple Silverlight 3 MediaPlayer using the MediaElement tag: <Border
I'm trying to build a simple scheduler using Quartz.NET, but when I try to

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.