# Wednesday, 27 August 2003

Werner Vogels posted a great article on what Web Services are and aren’t, and why they represent Service Oriented Architecture, and not a Distributed Object Architecture.  Don’t let the name SOAP fool you.

Wednesday, 27 August 2003 16:01:35 (Pacific Daylight Time, UTC-07:00)  #    Disclaimer  |  Comments [0]  | 

Just finished struggling through yet another Windows Forms issue that had us completely baffled.  Writing multi-threaded WinForms applications brings up some very interesting challenges, and involves learning a bunch of new stuff, some of which is not at all obvious.  See my previous posts on InvokeRequired for a good example. There end up being some really interesting consequences of the boundary between the CLR only world, and the underlying implementation where windows have to deal with message pumps.  While WinForms insulates us from the real underlying PeekMessage calls, they are still there, and at some point the rubber has to meet the road, so to speak.  The problem I just had to deal with is way to complicated to even summarize here, but the core of the problem was that if I call Thread.Sleep on short intervals in a loop with calls to Application.DoEvents in between, the GUI doesn’t update correctly, but if I call Form.ShowDialog then it does.  WinForms knows something about message pumping that I don’t, which doesn’t really come as a surprise. 

Some days I think that this is way harder than MFC was, but on other days (like today) I realize that the real difference is that WinForms frees us to hurt ourselves in new and different ways that were too hard to achieve before.  I can only think that’s a step in the right direction. J

Wednesday, 27 August 2003 15:33:59 (Pacific Daylight Time, UTC-07:00)  #    Disclaimer  |  Comments [0]  | 

It’s a bit off topic, and not strictly speaking technical, but I’ve got to say I’m totally digging Rhapsody.  For a very reasonable fee ($25 a quarter) I can now listen to something like 20,000+ albums from anywhere I’m online.  Much easier than trying to haul around 10 or 20 Gb worth of MP3s, and I can play music from anywhere there’s a broadband connection.  There’s no activation or other association with a given machine, so as long as I remember my credentials I can listen from anywhere (one place at a time, of course).  So if I really want to listen to Rob Zombie, Fatboy Slim and the Rolling Stones in the space of 20 minutes ( I hadn’t realized what a Rob Zombie fan I really am ) it’s all there.  There are a few noticeable holes in their collection, but they’re adding new albums all the time, so I have high hopes.  And best of all, it’s legal and guilt free.  And if I really must listen to something when I’m not online (which doesn’t seem to be all that often) then I can burn most of their tracks to CD for $.79, which is comparable to Apple of Buy.com’s offerings. 

Groovy

Now if only Rhapsody supported the blogging plug-in… (Right now it’s Mad Flava by Fatboy Slim)

Wednesday, 27 August 2003 15:10:18 (Pacific Daylight Time, UTC-07:00)  #    Disclaimer  |  Comments [0]  | 
# Wednesday, 13 August 2003

Fixed.  If we move all our initialization code to run after the controls have been fully created and added to their parent’s Controls collection then everything works just fine, and InvokeRequired returns what it should.  Again, the more I think about this problem the more it makes sense that it would work this way.  However, what I would expect is for the call to InvokeRequired to throw an exception if it can’t really determine the right answer (e.g. isn’t initialized properly?) rather than just returning false.  If it had thrown an exception we would have found the problem right away, rather than having to discover it the hard way.  And since calling InvokeRequired on a control without a parent is apparently an exceptional case, it would be the right thing to do. 

If anyone who reads this is or knows a PM on the WinForms team, you might mention this issue. J 

Wednesday, 13 August 2003 14:35:03 (Pacific Daylight Time, UTC-07:00)  #    Disclaimer  |  Comments [0]  | 
# Monday, 11 August 2003

I spent some time late last work working with my colleague Jeff Berkowitz on what seemed like a pretty sticky problem.  He’s got some more info about the problem here, but the quick description is that we were in a situation where Control.InvokeRequired was apparently returning an incorrect value.  Our code was clearly running on a thread other than the GUI thread, and yet InvokeRequired returned false.  Disconcerting to say the least. 

Jeff spent quite a bit of time tracking down the problem over the weekend, and the conclusion that he came to is that if you want to call Control.InvokeRequired and get a rational and deterministic answer, the control you are calling it on must be embedded in the control containment hierarchy all the way up to a top level Form.  What we were doing involved creating controls but holding them in memory without putting them into the “visual” hierarchy of the application, meaning that they were not contained by a parent Control or Form.  Apparently if that is the case, InvokeRequired doesn’t return the correct results.  (Note that so far this is based on experiential evidence and not “scientific” data.)

The longer I think about this the more I’m not surprised that this is the case, but I’ve never seen any hint of documentation (from MS or otherwise) that indicates that this is true.  The solution (at least for us) is pretty straightforward, and involved moving some initialization code until after all the controls have been fully created and sited in forms.  Not a big deal, but it does prevent us from doing some up front initialization in a place where our users wouldn’t notice it.  Now it’ll take a progress dialog.  Seems like a reasonable price to pay, but it would, of course, be nicer if it worked the way we expected it to.

Monday, 11 August 2003 16:05:21 (Pacific Daylight Time, UTC-07:00)  #    Disclaimer  |  Comments [0]  | 
# Tuesday, 05 August 2003

So far I’ve done some experiments with a couple of the options I mentioned in my last post.   I tried styling the incoming XML document into something I could read into a dataset, and then used SqlDataAdapter.Update to persist the changes.  This works pretty well, but the biggest issue ends up being foreign key constraints.  I think you’d either have to do some pretty funky stuff in the stylesheet, or clean up the foreign keys once they were in the dataset, although that only works if your dataset doesn’t have constraints to begin with. 

Then I tried OPENXML, and I’ve got to say that so far that’s the way I’m leaning.  It turned out to make things much easier if I style the incoming XML into a simpler format (without all the namespaces) then pass that to OPENXML.  The OPENXML code turned out to be way less hairy than I had thought it might be, and I can handle the transaction in the stored proc rather than using DTC transactions.  All in all, not a bad thing.  It’s almost enough to make me not care if things change in Yukon in ways that would make this not work, or be obsolete.  It’s pretty slick in the near term.  I haven’t tried any performance testing, but it seems to me that the OPENXML solution is faster. 

I could try the other option of parsing the XML in C# and then making transacted ADO.NET calls to persist the data, but I don’t really want to go there.  It’s the business-layer XML parsing I’m trying to get rid of, and it’s a lot more code. 

Tuesday, 05 August 2003 19:34:08 (Pacific Daylight Time, UTC-07:00)  #    Disclaimer  |  Comments [0]  |