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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:52:21+00:00 2026-05-17T23:52:21+00:00

I am building a simple class to hold related methods. Part of this code

  • 0

I am building a simple class to hold related methods. Part of this code includes synchronising to a database. The built in SyncOrchestrator class includes a SessionProgress event handler which I can wire up an event to.

What I would like to do is instance my class and then hook up an some code to this event so that I can display a progress bar (ill be using BGWorker).

So, my question is probably c# 101, but how do I expose this event through my class the correct way so that I can wire it up?

Thanks

  • 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-17T23:52:21+00:00Added an answer on May 17, 2026 at 11:52 pm

    I think you’re looking for something like this:

    (I also suggest you read the Events tutorial on MSDN.)

    public class SyncOrchestrator
    {
        // ...
    
        public event EventHandler<MyEventArgs> SessionProgress;
    
        protected virtual void OnSessionProgress(MyEventArgs e)
        {
            // Note the use of a temporary variable here to make the event raisin
            // thread-safe; may or may not be necessary in your case.
            var evt = this.SessionProgress;
            if (evt  != null)
                evt (this, e);
        }
    
        // ...
    }
    

    where the MyEventArgs type is derived from the EventArgs base type and contains your progress information.

    You raise the event from within the class by calling OnSessionProgress(...).

    Register your event handler in any consumer class by doing:

    // myMethodDelegate can just be the name of a method of appropiate signature,
    // since C# 2.0 does auto-conversion to the delegate.
    foo.SessionProgress += myMethodDelegate;
    

    Similarly, use -= to unregister the event; often not explicitly required.

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

Sidebar

Related Questions

As part of a test bench I'm building, I'm looking for a simple class
I'm building a simple dropdown where I'd like to add a class to parent
I am building a simple PHP daemon script, using a php Daemon class provided
As a proof of concept, I'm building this extremely simple Twitter Friends crawler. Here's
I'm building a simple Todo List application where I want to be able to
I am building a simple Django app that will use scribd to display documents.
I'm building a simple ASP.NET web application in VS 2008 with a SQL 2005
I'm building a simple ice sliding puzzle to test uses of allegro. So far
I'm building a simple accounting app to be used for personal finance. A user
I'm building a simple web-based RSS reader in Python, but I'm having trouble parsing

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.