---
title: "Defensive event publishing, a different approach"
url: "https://osherove.com/blog/2005/4/8/defensive-event-publishing-a-different-approach.md"
canonical: "https://osherove.com/blog/2005/4/8/defensive-event-publishing-a-different-approach.html"
published: "2005-04-08T09:59:00"
updated: "2005-04-08T09:59:00"
tags: [".Net Quotations"]
author: "Roy Osherove"
description: "Eric has posted a nice example of invoking \"safe events\" without using the threadpool , as was mentioned in my own article here. You should definitely go read his post and see his code, since it's different way of…"
usage: "Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page)."
license: "https://creativecommons.org/licenses/by/4.0/"
---

# Defensive event publishing, a different approach

By Roy Osherove April 8, 2005 In [.Net Quotations](https://osherove.com/blog/category/net-quotations)

**Historical article** · Originally published April 8, 2005; technical details may be outdated.

[Eric](http://www.randomtree.org/eric/techblog/) has [posted a nice example of invoking "safe events" without using the threadpool](http://www.randomtree.org/eric/techblog/archives/2005/04/defensive_event_publishing_for_remoting.html), as was mentioned in my own article here. You should definitely go read his post and see his code, since it's different way of looking at things, and it's always good to see other perspectives.

Personally, I find it a bit more cumbersome, but then again, it lets you have a little more control on your events, and is more fit for situations which are not pure "fire and forget".

"_Several months ago, Roy Osherove posted a discussion of_ [_Defensive Event Publishing in .Net_](http://weblogs.asp.net/rosherove/articles/DefensiveEventPublishing.aspx) _that discussed various problems with the "normal" methods of event publishing and raising in .Net. The naive programmer merely calls MyEvent(sender, eventArgs), never suspecting the minefield into which he or she is blithely strolling. Roy's post suggests several progressively more cautious methods of raising events to protect oneself against "bad" clients. At the time I commented that further improvements could be made, specifically to both avoid using Threadpool threads and to detect which callers are bad. I thought I'd finally get around to explaining what I meant and actually providing a solution I've used in the past."_

## More in .Net Quotations

[All posts in .Net Quotations](https://osherove.com/blog/category/net-quotations)

- Apr 8, 2005

    ### [\[Free eBook\]FIT for Developing Software: Framework for Integrated Tests](https://osherove.com/blog/2005/4/8/free-ebookfit-for-developing-software-framework-for-integrat.html)

- Apr 8, 2005

    ### [TimedLock class: helping find and avoid deadlocks in your multithreaded code](https://osherove.com/blog/2005/4/8/timedlock-class-helping-find-and-avoid-deadlocks-in-your-mul.html)

- Apr 6, 2005

    ### [Solving Binary serialization versioning conflicts - The HashTable problem](https://osherove.com/blog/2005/4/6/solving-binary-serialization-versioning-conflicts-the-hashta.html)

- Mar 11, 2005

    ### [CLR Performance Q&A, and how it relates to unit testing and mock objects](https://osherove.com/blog/2005/3/11/clr-performance-qampa-and-how-it-relates-to-unit-testing-and.html)


---

## About the author

**Roy Osherove**: Senior Solutions Architect at AWS working on AI for production and AI-driven development; author of The Art of Unit Testing and Elastic Leadership, with about 20 years of consulting and training on unit testing, TDD, team leadership and continuous delivery.

### Sites

- [RobotPaper](https://robotpaper.ai/): This blog: AI patterns and anti-patterns, AI and coding agents, and engineering leadership.
- [osherove.com](https://osherove.com): Roy's personal site. Author of The Art of Unit Testing and Elastic Leadership; consulting and training on unit testing, TDD, team leadership and continuous delivery, plus about 20 years of blog posts.
- [The Art of Unit Testing](https://www.artofunittesting.com): The Art of Unit Testing, 3rd Edition (Manning): readable, maintainable, trustworthy unit tests, plus TDD workshops in C#, JavaScript, Java and Kotlin.
- [5whys.com](https://www.5whys.com): Roy's writing on software team leadership: self-organizing teams, surviving chaos, learning mode and the Elastic Leadership model.
- [Pipeline Driven](https://pipelinedriven.org): Continuous delivery and DevOps practices: build patterns, pipeline-friendly testing, DevOps metrics and enterprise DevOps.
- [Elastic Leadership](https://www.elasticleadership.com): Elastic Leadership, Roy's framework for software team leaders (survival, learning and self-organizing modes).

### Social

- X: https://x.com/royosherove
- LinkedIn: https://www.linkedin.com/in/osherove/

### Contact

- Contact form: https://forms.gle/jQSx5KoXvrVA1JCK7

### License

Licensed under CC BY 4.0 — reuse, quote and adapt with attribution (Roy Osherove, link to the original page). License: https://creativecommons.org/licenses/by/4.0/
