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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:38:01+00:00 2026-05-14T14:38:01+00:00

I wrote an application in WPF / VB and separated the business logic and

  • 0

I wrote an application in WPF / VB and separated the business logic and UI into different projects.

The business layer uses a serial port which runs on a different thread, Now that I’m trying to write a command line interface for the same business layer, it seems to fail when .Invoke() is called. (no error, just doesn’t work)

I’m pretty sure the reason I had to add in checkaccess and .invoke was because I have collections that would be changed during processing the serial port data and wanted the NotifyCollectionChanged to be handled by WPF data binding.
(The reason I’m not 100% sure is because it was months ago I wrote that part and it all worked great from the GUI, now adding the console app has made me rethink some of this)

I would like my business layer to run these processes on the thread they were created, I need this to work from both my GUI version and the command line version.

Am I misusing the Dispatcher in my business layer? Is there a better way to handle an event from the serial port, and then return to the main thread to processes the data?

Updated:

Private Delegate Sub NewDataRecieved(ByVal byteBuffer() As Byte)
Private Sub DataReceived(ByVal byteBuffer() As Byte) Handles _serial.DataRecieved
    If _dispatcher.CheckAccess() Then
        ProcessTheData
    Else
        Dim dataReceivedDelegate As NewDataRecieved
        dataReceivedDelegate = New NewDataRecieved(AddressOf DataReceived)
        _dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, dataReceivedDelegate, byteBuffer)
    End If
End Sub
  • 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-14T14:38:02+00:00Added an answer on May 14, 2026 at 2:38 pm

    Invoke doesn’t do anything because you don’t have a dispatcher running, to get any services from a dispatcher you have to call Dispatcher.Run ( http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatcher.run.aspx )

    Now, your problem is that calling Dispatcher.Run will make WPF take control of the thread – and that is probably not what you want to do in a console application.

    I think the best option in your situation is to remove the thread synchronization code (anything that talks to a dispatcher) from your business layer and into wrapper objects.

    The WPF app can continue to work as before by using the wrapper objects and the console app can use the “raw” business layer directly.

    Update: here is an example of the wrapper below, you have to create a method/property for every public member of the original class that does the threading work and calls the original object.

    public class BOWrapper : INotifyPropertyChanged
    {
        private BO _bo;
        private Dispather _dispather;
    
        public BOWrapper(BO bo, Dispatcher dispather)
        {
            _bo = bo;
            _dispather = dispather;
            _bo.PropertyChanged += BOPropertyChanged;
        }
    
        public string SomeValue
        {
            get { return _bo.SomeValue; }
        }
    
        private void BOPropertyChanged(object sender, PropertyChangedEventArgs ea)
        {
            _dispatcher.Invoke(
                new Action<PropertyChangedEventArgs>(
                    e=>
                    {
                        var handler = PropertyChanged;
                        if(handler!=null) handler(this,e);
                    }),ea);
        }
    }
    

    The wrapper class is 100% boilerplate code and you probably can use some code generator to create it, maybe even use something like DynamicProxy ( http://www.castleproject.org/dynamicproxy/index.html ) to generate it automatically at runtime.

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

Sidebar

Related Questions

I wrote an application that currently runs against a local instance of MySql. I
I wrote an application recently, which relies on OpenID for authentication. A lot of
I wrote an application in Java and when it runs on one customer's computer
I wrote a small PHP application several months ago that uses the WordPress XMLRPC
I have written a WPF application that I want to port to Silverlight 2.
I have a WPF application in which I have a hook at PreviewTextInput, through
I'm trying to learn how to design an application which has several different user
I wrote little WPF application with 2 threads - main thread is GUI thread
I have a problem in a WPF application. I wrote this code: public partial
in WPF application I load a list of business objects by WCF to a

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.