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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:56:55+00:00 2026-06-06T19:56:55+00:00

I am working on a WPF project, using MVVM and Microsoft Prism libraries .

  • 0

I am working on a WPF project, using MVVM and Microsoft Prism libraries. So, when I need to communicate through classes I use the class Microsoft.Practices.Prism.MefExtensions.Events.MefEventAggregator and I publish events and subscribe methods as below:

To publish:

myEventAggregator.GetEvent<MyEvent>().Publish(myParams)

To Subscribe:

myEventAggregator.GetEvent<MyEvent>().Subscribe(MySubscribedMethod)

But my question is: Is there a way to return some data from the “Subscribed method” after publishing an event??

  • 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-06T19:56:57+00:00Added an answer on June 6, 2026 at 7:56 pm

    As far as I know, if all the event subscribers are using the ThreadOption.PublisherThread option (which is also the default), the event is performed synchronously and the subscribers can modify the EventArgs object, so you could have in the publisher

    myEventAggregator.GetEvent<MyEvent>().Publish(myParams)
    if (myParams.MyProperty)
    {
       // Do something
    }
    

    The subscriber code would look like this:

    // Either of these is fine.
    myEventAggregator.GetEvent<MyEvent>().Subscribe(MySubscribedMethod)
    myEventAggregator.GetEvent<MyEvent>().Subscribe(MySubscribedMethod, ThreadOption.PublisherThread)
    
    private void MySubscribedMethod(MyEventArgs e)
    {
        // Modify event args
        e.MyProperty = true;
    }
    

    If you know that the event should always be called synchronously, you can create your own base class for events (instead of CompositePresentationEvent<T>) which overrides the Subscribe method, and only allow subscribers to use the ThreadOption.PublisherThread option. It would look something like this:

    public class SynchronousEvent<TPayload> : CompositePresentationEvent<TPayload>
    {
        public override SubscriptionToken Subscribe(Action<TPayload> action, ThreadOption threadOption, bool keepSubscriberReferenceAlive, Predicate<TPayload> filter)
        {
            // Don't allow subscribers to use any option other than the PublisherThread option.
            if (threadOption != ThreadOption.PublisherThread)
            {
                throw new InvalidOperationException();
            }
    
            // Perform the subscription.
            return base.Subscribe(action, threadOption, keepSubscriberReferenceAlive, filter);
        }
    }
    

    then instead of deriving MyEvent from CompositePresentationEvent, you derive it from SynchronousEvent, which will guarantee you that the event will be called synchronously and that you will get the modified EventArgs.

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

Sidebar

Related Questions

I'm working on a WPF project using Prism and MVVM, I'm new using this
I'm working on a WPF project using MVVM and I'm trying to implement a
I would like to use an MVVM in a WPF project I'm working on,
Hy guys! I am currently working on a little WPF project using MVVM via
I m working in a WPF MVVM Project and I am using one Wpf
Im working on a middle size project, using WPF. Need DataGrid, suitable for the
I'm working in a WPF project, I'm using the MVVM patter in my project.
I'm working on a project using WPF and MVVM with Entity Framework 4.3, and
I am working on a WPF MVVM Project. Now i have a DataGrid in
I have been working on a C# 4.0 WPF project and need to figure

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.