Surviving WinForms
Let's face it, WinForms is here to stay. Whatever new hotness comes and goes in the world of web, many developers will find themselves supporting the desktop apps of yesteryear (or yesterdecade).
The apps work, representing thousands of hours of effort and business rules, fine-tuning and bug fixes, and companies won't needlessly convert anytime soon. In truth, it might not even be wise... an app converted to a new platform could very well introduce dozens or hundreds of new bugs.
So to all my fellow devs that find themselves supporting the old coldness, let's make the best of it...
Avoiding Anti-Patterns
- Using nameof to avoid magic strings (blog post, source code)
Clarity / Conciseness
- Checking for null using the null-conditional and null-coalescing operators (blog post, source code)
- Local functions in C# (aka nested methods) (blog post, source code)
- Named arguments in C# - pass what you want and forget the rest (blog post, source code)
- Using string interpolation to craft readable strings (blog post, source code)
Debugging / Logging
- How to log errors in WinForms using NLog (blog post, source code)
- A dev-friendly error box with links to the docs (blog post, source code)
Testing
- Mocking the MessageBox (blog post, source code)
- Using MVP to test a WinForms app (blog post, source code)
Threading
- Using Async, Await, and Task to keep the WinForms UI responsive (blog post, source code)
- Turning a BackgroundWorker into a Task with TaskCompletionSource (blog post, source code)
Web
CEFSharp
- Hosting a simple webpage in WinForms with CEFSharp (blog post, source code) (part 1)
- Displaying an IIS hosted site in CEFSharp (blog post, source code) (part 2)
Other Resources
Other interesting and helpful links, in no particular order: