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

  • Home
  • SEARCH
  • 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 6927629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:04:48+00:00 2026-05-27T11:04:48+00:00

I need to access a static property from a console application (NServiceBus selfhost) while

  • 0

I need to access a static property from a console application (NServiceBus selfhost) while the console application is running. Is this possible?

When the NServiceBus console is executed, a static property is set in my starup class:

    public static IBus Bus { get; private set; }

    public static void Init()
    {
        Bus = NServiceBus.Configure.With()
            .Log4Net()
            .DefaultBuilder()
            .XmlSerializer()
            .MsmqTransport()
                .IsTransactional(false)
                .PurgeOnStartup(false)
            .UnicastBus()
                .LoadMessageHandlers()
                .ImpersonateSender(false)
            .CreateBus()
            .Start();
    }

Another class within the NServiceBus console application calls for the static bus property. I am only referencing the associated console application dll to obtain this message object. I create this message object to call it’s public method “SendRouteMessageReceived”. However, I need to set the bus here to the bus that was instantiated during execution of the NServiceBus console (shown in code above).

public class OrderMessaging
{
    public IBus Bus { get; set; }

    public void SendRouteMessageReceived(LabRoutingUpdateMessage routingUpdateMessage)
    {
        Bus.Send(new RouteMessageReceived(routingUpdateMessage));
    }

}

C# code from my WPF application to instantiate the message object and send the message to NServiceBus:

MyBus.OrderManagement.OrderMessaging routeMessageReceived = new MyBus.OrderManagement.OrderMessaging();

I use the following code from my WPF application to start the NServiceBus (selfhost)console application:

System.Diagnostics.Process.Start("MyApplication.exe");

Can someone provide example code how I might execute a console application from within a WPF application and access a static property that was instantiated in the console app?

Update: I must add that the Bus object is started a separate host console exe, while I also start the “Message” NServiceBus console separately via this code:

System.Diagnostics.Process.Start("MyApplication.exe"); (this is the exe where the bus is instantiated – this is the selfhost service bus console application)

System.Diagnostics.Process.Start("NServiceBus.Host.exe"); (this is the service host where my message object class is used in my wpf application)

Is there a better way to start both services outside visual studio to keep the static bus property shared between both hosted services?

  • 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-27T11:04:48+00:00Added an answer on May 27, 2026 at 11:04 am

    My advise: Don’t. You want interprocess communication through messaging (ie via NServiceBus and MSMQ). Not via windows api and other complicated stuff.
    Define your messages in a separate assembly. Define your Init function (bootstrap method) in a shared assembly and give each application its own static IBus, wich is initialized once at the start of each application through the Init function.
    I suspect you want a basic publisher / subscriber construction. A nice example to accomplish this is given here.

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

Sidebar

Related Questions

Possible Duplicate: Why can I only access static members from a static function? While
I've got an app running maximized in a borderless window and need access to
I need to access RMI methods from a client front end. For different reasons,
I need to access the bluetooth network interface from Java. All local network interfaces
I need to access a mysql database from c# code but I would prefer
I need to get access to a variable from another class and I keep
I have a winforms app, and I need to access the Handle property of
I have two different modules that need access to a single file (One will
I can't create a NT account for everyone that need access to the reports.
I need to access the OpenGL state variables (such as the MVP matrices) in

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.