---
title: "UI Threading - A Very Simple Solution"
url: "https://osherove.com/blog/2003/5/20/ui-threading-a-very-simple-solution.md"
canonical: "https://osherove.com/blog/2003/5/20/ui-threading-a-very-simple-solution.html"
published: "2003-05-20T06:56:00"
updated: "2003-05-20T06:56:00"
tags: [".Net Original", "Tips & Tricks"]
author: "Roy Osherove"
description: "God loves the simple solutions. It turns out that there is a really simple solution to the problem of working with UI threads.Much simpler then mine . I was given this simple pattern by a guy on the win_tech_off_topic…"
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/"
---

# UI Threading - A Very Simple Solution

By Roy Osherove May 20, 2003 In [.Net Original](https://osherove.com/blog/category/net-original), [Tips & Tricks](https://osherove.com/blog/category/tips-tricks)

**Historical article** · Originally published May 20, 2003; technical details may be outdated.

God loves the simple solutions. It turns out that there is a really simple solution to the [problem](http://dotnetweblogs.com/rosherove/posts/6554.aspx) of [working](http://dotnetweblogs.com/jlerman/posts/6562.aspx) with UI threads.Much simpler then [mine](http://dotnetweblogs.com/rosherove/story/7171.aspx). I was given this simple pattern by a guy on the win\_tech\_off\_topic list. Here it is:

_"I've read your article, and there is a simple pattern for multi-threaded_

_UI: in your event, you check the InvokeRequired parameter._

_Eg: (this hasn't been anywhere near a compiler)_

_

protected void windowsform\_Event(object sender, EventArgs e)

{

if (this.InvokeRequired)

{

this.Invoke(new EventHandler(windowsform\_Event), new object\[\] { sender, e });

return;

}

// do your magic here, and it will always be on the UI thread

}

_

_Best wishes, James Berry"_

_Good one! I've been reading about UI threading in one of the past MSDN issues. The **InvokeRequired** Property returns true if the thread that reads it is not the UI thread of the control. Simple, elegant. What more could one ask for?_

## More in .Net Original

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

- May 26, 2003

    ### [Strong Vs. Loose Typing/Loose binding](https://osherove.com/blog/2003/5/26/strong-vs-loose-typingloose-binding.html)

- May 21, 2003

    ### [The Books I Really Really Want](https://osherove.com/blog/2003/5/21/the-books-i-really-really-want.html)

- May 19, 2003

    ### [Ingo Rocks Too](https://osherove.com/blog/2003/5/19/ingo-rocks-too.html)

- May 19, 2003

    ### [Articles, Articles, Articles!](https://osherove.com/blog/2003/5/19/articles-articles-articles.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/
