To Invoke or not to Invoke? That is the Question!

Yesterday I was having a problem with my UI on my smart client application.  I’m using the offline data block from the MS Patterns and Practices group.  It took awhile to learn how to use this, but now that I am I really like it.  It uses a separate thread to do the data requests.  Well, as most applications would I wanted that thread to update a progress bar on my UI to tell the user how many requests where in the queue and when they where completed.

This sounds like it should be easy, but hopefully most of you know that a separate thread cannot update a UI element on the main GUI thread.  This article talks about why and how to do it using the Invoke() method.  I was using the Invoke() method and everything was running fine at first.  However, after I started testing the application started to deadlock\freeze.  I put lock statements all around my code to try and avoid the problem to no avail.

Finally I ran across this post from Kristof Verbiest which explained my problem.  The Invoke() method IS NOT an asynchronous call.  The code will wait for the method called within the Invoke() to complete before it moves on.  So, what was happening was my main thread was waiting for the Invoke() and also calling the thread to do another request.  This caused the deadlock.  The post from Kristof explained that the BeginInvoke() method IS an asynchronous and will allow the code to continue.  By changing my Invoke() calls to BeginInvoke() I fixed my problem.  Thanks Kristof!

So the answer is to not Invoke(), but to BeginInvoke()…

Posted in | 2 comments

Application UI Design Mistakes

I came across this article in my daily web surfing.  I’d like to think I know all these rules, but they are good to keep in the back of your head and revisit when you start desigining UI for a new project.

Posted in | 0 comments

South Colorado Launch 2008

It’s official!  Friday, April 4th from 2:00 – 6:00 PM all three South Colorado User Groups (.Net, SQL Server and Windows Server) will be collaborating to bring you some great content related to the new releases of Microsoft technologies.  All the sessions are still being finalized and the official schedule should be up soon.  Keep your eye on the official site here for more details.

I’m sure there will be great content, but please plan on attending for no other reason than to connect with the Microsoft community here in the South Colorado area.  Learning from our peers is a fun way to think outside the box and come up with new ideas to solve everyday issues.  I hope to see you there.

If the weather cooperates you should just take the whole day off and get in 18 holes before attending.

Posted in | 0 comments

WCF 404 Page Not Found

Just a quick note about hosting your WCF service in IIS.  I had some problems getting this to work yesterday.  Everything worked great on my developement machine.  I had my WCF service serving up data and functionality to my ASP.Net front end and a Windows Service I’m using for automation and monitoring.  I moved everything out to IIS on the test machine, configured the sites in IIS and started testing.  I kept getting HTTP 404 Page Not Found Errors while trying to reach my WCF service.  I found a great blog post from Jean-Paul Smit that finally solved my issue.  I had to do number 3 in his list of possible solutions. 

%windir%\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ServiceModelReg.exe /s:W3SVC

Once I ran this from the cmd prompt everything worked great.  Thanks Jean-Paul!

One final note: If you don’t have the file mentioned above you need to download and install .Net Framework 3.0.  I ran accross this on one of my servers. 

Posted in | 13 comments

Serializing a Generic Dictionary

So, I created all this fantastic code (God, I love my work) that used a singleton to hold some data that I needed throughout my app.  One of the properties in that class was a generic dictionary.  Well, as I got further into the application I came across the need to persist this data to an XML file.  Naturally (almost instinctively, which means I have no life), I wrote the few lines of code to use the XMLSerlializer to save this to disk.  The problem is the generic dictionary is not serializable.  I was dreading the idea of changing the way I was storing and using that dictionary all through out my app.

To make a long story short, (too late) I did a search and found this post from Paul Welter’s blog.  All I needed to do was create this class in my project, change the data type on my dictionary in my Singleton and it all worked and serialized perfectly.  Thanks Paul!

Posted in | 0 comments