September 2006 - Posts

UI Controls and Threading
28 September 06 10:08 AM | MikeD

Steve posted about a problem with updating a UI control from a non-UI thread. In his case, the exception that was produced wasn't clear as to what was causing the problem. On the mobile device the exception that was generated was:

NotSupportedException
An error message cannot be displayed because an optional resource assembly containing it cannot be found.

Nice, hey? Well, Threading 101 says that you should never update the UI from a non-UI thread - there is only one, and the control classes know whether they are executing on the UI thread or on another thread, through the InvokeRequired property, and, thankfully, you can execute code on the UI thread using the Invoke method of the control (or form).

Anyway, the pattern that event handlers should be using is this:

Public Sub OK_Click(sender as Object, e as EventArgs) Handles OK.Click

If Me.InvokeRequired Then

Me.Invoke(New EventHandler(AddressOf Me.OK_Click), New Object(){sender, e}))

Else

Me.TextBox1.Text = "Something"

End If

End Sub

The Smart Client Composite Application Block has an eventing mechanism that allows you to publish events from any object, and subscribe to them from any object, simply by using string constants for the event names in an attribute. Look at the EventBroker namespace for more details. The nice thing about subscribing to events is that you can specify that you want the event handler to be fired on the UI thread and the event broker does that for you, so you don't need to do the Me.InvokeRequired check.

Unfortunately, the standard Microsoft controls don't always follow this practice in their event handlers.

For example, recently I was working on a project that had a custom collection of business objects, implemented as a BindingList<of MyEntity>. My class MyEntity implemented the interface System.ComponentModel.INotifyPropertyChanged, and whenever I changed a property value, I raised the PropertyChanged event. The nice thing about inheriting from BindingList and using the PropertyChanged event is that the UI binding is already handled for you. I set the data source of a DataGrid control in my form to this inherited BindingList and the list nicely displayed in my grid.

However, when I had a background thread add something to my BindingList, it would cause a threading exception, because the DataGridView's handling of the ListChanged events from the BindingList didn't check for Me.InvokeRequired.

I found I had a few possible approaches to this problem:

  • Inherit the DataGridView control and override the event handlers to "do it right". (nope, the handler methods aren't exposed)
  • Get a System.Windows.Forms.WindowsFormsSynchronizationContext handle in my inherited BindingList and use its methods to add stuff to the list on the UI thread (ugly: I didn't want a reference to System.Windows.Forms in the business assembly I had that list in, and this just moves the Me.Invoke stuff into the middle tier. But I did implement this mechanism for a time then decided to remove it.)
  • Implement the BindingList in the UI layer and have the business layer raise events about new or changed entities - all the list management happens in the UI by responding (on the UI thread) to the events from the business layer (this is the one I chose in this case, because maintaining a list of entities wasn't needed in the business layer).

 Throughout this process, I keep thinking that I wish that I could just mark an event handler as needing to execute on the UI thread and let the .NET Framework do this for me. An attribute like <UIThreadExecute> for an event handler could "just do it" for me. So the above code example would end up looking like this instead:

<UIThreadExecute()> _ 

Public Sub OK_Click(sender as Object, e as EventArgs) Handles OK.Click

Me.TextBox1.Text = "Something"

End Sub

Wouldn't that be simple?

Filed under: ,
Enterprise Library v3 plan is released.
27 September 06 08:32 AM | MikeD

The Patterns and Practices group at MSDN have released their initial plans for Enterprise Library v3.

In a nutshell, here is their list:

As at our Vision/Scope milestone, the minimal credible list line includes the following features:

  • Medium Trust support
  • Manageability extensions for configuration (WMI, Group Policy)
  • Simple Strong-naming
  • Mini-Factory for building your own blocks and providers
  • Validation Application Block
  • Exception Handling: WCF integration (exception shielding / fault mapping)
  • Logging: WCF pipeline integration
  • AuthZ: WCF Pipeline integration

Once we get through this list, we have prioritized a backlog of additional features. Currently this list looks like this:

  • Config Tool: Embedded in the Visual Studio IDE 
  • DAAB: SQL Everywhere support
  • DAAB: Richer transactions support
  • Docs: More code samples
  • Docs: Detailed documentation for ObjectBuilder
  • DAAB: Batch support
  • Config Tool: Edit AppSettings and other .NET settings
  • Config Tool: Environmental Overrides
  • Config Tool: Encryption Support
  • Config Tool: Improved type loading behavior when assemblies can't be found
  • Logging: Rolling flat file TraceListener
  • Logging: Local or UTC timestamps in formatted log messages
  • Logging: Reflected property tokens
  • Ability to create custom production installs
  • Ability to create custom developer installs
  • Exception Handling: Localization of exception messages
  • DAAB: ODP.NET provider support
Looks like a great lineup at Patterns and Practices Summit...
22 September 06 10:51 AM | MikeD

Look at this lineup of sessions at the Patterns and Practices Summit in Redmon Oct 9-12.... 

http://www.pnpsummit.com/west2006sessions.aspx

 I'd like to see verything, but if I had to pick....

 Dependency Injection Architecture

Application Framework Projects in IT

CSLA Framework - Lessons Learned

Architecting for Security

Evolving to Patterns

Contractual Zen

"The Agile Talk on Agility"

Continuous Integration

TDD for GUIs

All of Day 4....

Ok, so I didn't actually narrow it down much.

I hope people who attend can blog as much about the sessions they attend as the TechEd bloggers did.

 

Filed under:
Some real-world Team System project experiences...
22 September 06 10:36 AM | MikeD | 1 comment(s)

Bill Simser in Calgary is using Team System with a Scrum template, and he mentioned hearing Joel's recently recorded Dot Net Rocks episode (which I've downloaded but haven't listened to - knowing Joel it will be clever and entertaining and inspiring all at once. Lucky me I get to hear Joel almost every day....)

Well, he's using it on a real project, and he's completed his first iteration. There are some interesting observations in his post, and I look forward to hearing more about this project.

We're using Team System and the "MSF for CMMI Process Improvement v4.0 Process Guidance" template for a project that uses similar technologies as Bill's list - except we're building for Mobile devices. We're using the Mobile Client Software Factory from Patterns and Practices, which includes a port of the Smart Client Composite Application Block and a bunch of GAT recipes.

 

Another good idea...
01 September 06 04:06 PM | MikeD

Ralf had another good idea

 He took a group of university Comp.Sci students and did a comprehensive 5-day workshop with them, using his methodologies.

It's a nice way to test out your methodologies on some high-energy people, plus I would think it's a good way to find co-op students you might consider hiring in the future.

He also mentioned two tools I hadn't heard of before: FinalBuilder, which is a build engine with a nice-looking GUI on it and a whack of features (or maybe more than a whack? I'd have to say it has a schwack of features.) Other than perusing their site, I don't know much about FB - it looks to be a dynamic product (three point releases since Nov 2005), but I wonder about extensibility options - pluggability, programmability, whatever.

Second, he talked a bit about SotoGraph which evaluates your project architecture and provides metrics on it. Sounds very interesting.

 

Filed under: ,
Rob Howard: marks of a maturing software organization...
01 September 06 09:54 AM | MikeD

Rob Howard had a great post:

We've [experienced] a shift from caring less about the underlying technology to how our software solves the user's problem. It's...probably one of the bigger "maturing" steps a software organization has to go through. You can tell when an ISV hasn't made this transition yet: the literature and announcements about their releases focus 100% on the underlying technology instead of how the software solves a particular set of problems for the people that use it.

If you had asked me 2 years ago about what we wanted Community Server  to become ... I would have [answered]: Provider Design Pattern, Server Controls, SQL Server, etc. In other words, I'd tell you about all the cool technology we were using and how we were using it. Today the answer is very different - in fact internally we judge our own success when customers use our software because of the problems it solves, not because of the technology it is built with.

For example, have you ever bought a car because of where the steel was made or because of the brand of the engine? A few people care about these things, but most people care more about: does the car drive good, are the seats comfortable, etc... 

Today...our philosophy is: (1) build it as quickly as we can (2) start using it as soon as possible (3) make it simple. Two years ago the phlosophy would have been: make it scalable, make it extensible, etc. Bottom line - If we had started these new projects 2 years ago I don't think they would ever be completed. Now I get worried when I sit in a design review and hear someone say, "we want to make it scalable and extensible". To me that translates to: "We don't know or understand our customer or the problems we are trying to solve, so we'll try to do everything in v1.0."

I'll admit that I fall into the trap of thinking about the underlying stuff like extensibility and scalability too early. I';m excited about the reading and thinking I am doing now on Test-Driven-Development and Contract-First-Design, as well as the Software Factory stuff we're doing internally, and I'm looking forward to using those concepts and practices on the next project I work on, I think those approaches can help with the mind-shift of developers and architects towards Rob's ideas and reduce "scope creep" induced by the "neato" geek factor that gets introduced to projects by architects, designers, and developers (such as myself).

 It's like "Just Enough" programming (perhaps this phrase has already been coined), borrowed from Just In Time inventory.

I can hear Joel saying "I told you this two years ago!"

More Posts