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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:25:03+00:00 2026-06-04T03:25:03+00:00

I subscribe to an event like this: private void CoupleOverlay(IMapVisual mapVisual) { overlay.DrawTilesProgressChanged +=

  • 0

I subscribe to an event like this:

private void CoupleOverlay(IMapVisual mapVisual)
{            
      overlay.DrawTilesProgressChanged += (s, e) => 
      {               
          mapVisual.DrawingProgress = e.ProgressPercentage;
      };
}

The application may call CoupleOverlay event many times so I need to unsubscribe DrawTilesProgressChanged event and subscribe again but because it is an anonymous event I can’t unsubscribe from it. I tried to convert to

private void CoupleOverlay(IMapVisual mapVisual)
{
    overlay.DrawTilesProgressChanged -=overlay_DrawTilesProgressChanged;                 
    overlay.DrawTilesProgressChanged +=overlay_DrawTilesProgressChanged;                 
}

private void overlay_DrawTilesProgressChanged(object sender, DrawTilesProgressChangedTileOverlayEventArgs e)
{       
    mapVisual.DrawingProgress = e.ProgressPercentage;
}

It is not working because mapVisual is not valid variable on overlay_DrawTilesProgressChanged method.

If I change the code to

private void CoupleOverlay(IMapVisual mapVisual)
{
    EventHandler<DrawTilesProgressChangedTileOverlayEventArgs> drawEvent = (s, e) =>
    {           
        mapVisual.DrawingProgress = e.ProgressPercentage;
    };

    overlay.DrawTilesProgressChanged -= drawEvent;
    overlay.DrawTilesProgressChanged += drawEvent;
}

It will not work cause drawEvent is a local variable and next time I call CoupleOverlay, it will create new one.

So How can I unsubscribe from this event handler? Or how can I know I’m subscribed to the event so I don’t need to subscribe again?

  • 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-04T03:25:04+00:00Added an answer on June 4, 2026 at 3:25 am

    it will not work cause drawEvent is local variable and next time I call CoupleOverlay, it will create new one.

    Indeed. You’d basically need to keep an instance variable instead of a local variable. The instance variable would effectively be “the currently subscribed event handler”. Then in CoupleOverlay you’d remove that event handler, create a new one (storing it in the variable) and resubscribing with it.

    An alternative would be to use a single event handler, but keep the “current” overlay and map visual as instance variables, used by the event handler. The CoupleOverlay method would then just need to update those variables.

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

Sidebar

Related Questions

In this case, is it bad to subscribe to the proxy CloseCompleted event? public
I'm trying to implement simple Event Bus I started like this: public class RegistrationData
What's the code to subscribe to an event like applicationWillResignActive in any place in
Is there currently a way to subscribe to an event of a wrapped set,
Is there a way to subscribe to the HttpApplication's BeginRequest event from Global.asax? What
In my class I want to declare an event that other classes can subscribe
I'm writing a topic-based publish/subscribe system in C++. My generic Event class has three
I am having trouble with the prism event aggregator. If I subscribe to, and
When you subscribe to an event in .NET, the subscription is added to a
Do you know how can I subscribe to an event of the base of

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.