Wednesday, July 13, 2005

Wednesday, July 20th, Randy Miller from Microsoft’s Visual Studio 2005 Team Systems group is coming to the Microsoft Offices to talk to the SPIN process User Group about the newest features of Visual Studio Team Systems and MSF Agile.  For more information, visit www.atlantaspin.org.  To prevent us from having three User Group meetings in a single week, we have elected to cancel the Monday meeting of the Atlanta Mobility User Group.

 

-- Matt Ranlett

posted with BlogJet

7/13/2005 9:45:32 PM (Eastern Standard Time, UTC-05:00)  #    Trackback
 Tuesday, May 17, 2005

Our own local Delta representative, Venkat Polisetti kicked the meeting off with a presentation about web services on the Compact Framework.  To begin, we compared synchronous web calls to asynchronous web calls:

Synchronous calls to web services:

  • can be dangerous because they have the possibility to freeze your user interface until the call completes in the primary thread. 
  • can be useful when the web method returns quickly and they are very easy to code. 

Asynchronous calls are:

  • executed on a different thread
  • more complex to code but
  • won’t freeze your UI when the web methods are slow to respond. 

Consuming a web services on the Compact Framework is pretty much the same as with web and winform apps.  When a web reference is added to a project, VS.Net creates a proxy class in the project and creates Begin and End methods for asynchronous operations.  Call the Begin method to initiate the web service call and call the End method to complete the web service call.  Venkat had prepared a demo for us to help us understand the complexities of using web services and the Compact Framework but his demo misbehaved a bit; the group tried to help out but the problems were initially beyond us.  So Venkat took a seat to work on his laptop and gave the floor to Dhamayanthi (D for short).  We ran out of time, so Venkat will show off his demo at the next Mobility UG meeting (he did get things working before the end of D’s presentation)

D started her presentation with a quick recap of polymorphism and inheritance.  The example she gave was to create a base class with multiple layers of inheritance – ProjectManager inherits from Employee which inherits from Person.  She then posed a question to the group, “How do you create the correct object when you don’t know which type of object is required up-front?”  The answer is to have the code look up the correct object type and then return to the calling function a reference of type MyAbstractBaseClass.  The reference will point to the correctly created object type.  This explanation of an Object Factory also encapsulates the concept of dynamic polymorphism.  We had spiraled out to a discussion of the Abstract Factory design pattern before D reigned us in and brought us back to dynamic polymorphism with an explanation of how delegates help simplify function calls which have the same signature.  She showed us how to use a delegate in C++ before showing us the differences in C#, making sure we all knew our roots. 

A delegate in C# is an object-oriented, type safe function pointer.  This complicated concept is easily explained by Chris Sell’s article, “.Net Delegates: A C# Bedtime Story”.  The story tells of an employee with a mean boss.  The employee writes code to notify his boss every time his status changes and the boss is happy.  But the next day the boss’s boss wants to be notified of the employee’s status changes.  This continues (adding bosses to the list) until the employee is forced to allow any interested party to subscribe to his status change events.  To do this, the employee defines an interface that the various bosses will implement (thus inheriting from the employee’s class (Interface Inheritance)).  Now anyone who implements the interface can pass their own objects into the interface methods as parameters.  This demonstrates polymorphism b/c the functions don’t know ahead of time which objects (bosses) are going to ask for status updates but they are able to take any objects that implement the interface. 

The next step in improving the code is to allow the boss objects to implement only the interface methods that they are interested in, not the ones they don’t care about.  The other thing we can improve upon is not requiring the use of specific method names.  Delegates are interfaces with one method which don’t require interface inheritance.  This is good b/c in .Net we are only able to derive from a single base class.  By taking each method in an interface and declaring them each as an individual delegate (essentially wrapping the method call in a delegate) the coupling is much looser – improving the flexibility of the code.  Delegates are capable of wrapping both instance methods (created when you new up an object) and static methods (which don’t require the creation of an object). 

A problem of delegates is that they are public methods and can be directly invoked (skipping the notification feature of the delegate).  Another problem of delegates is that a delegate only returns to the last registrant.  If multiple people register for the event and they don’t register for an event with +=, then they will erase all the other registrations.  To prevent this, wrap the delegates in events.  The framework will then create the register and unregister events.  If someone then tries to use the event without using += syntax they get a compiler warning.  D was on the ball tonight, even breaking out ILDASM to show us what was happening under the covers with delegates and events, and how += completed and -= completed are both overloaded in IL as add_completed and remove_completed (where completed is our delegate name). 

The next problem we had to solve was how to get the return value of each delegate or event call when multiple objects (bosses) have registered.  The answer is to use the event’s .GetInvocationList method and save the results in a delegate variable.  Of course, we don’t want to do this synchronously – we need to make sure we can pass by registrants who aren’t ready to report their results.  This is where the BeginInvoke method of a delegate comes into play – you can call the event’s BeginInvoke on the method without passing anything in or retrieving anything out.  This is the Fire and Forget method of handling this problem.  A better way to handle this problem is to use the IAsynchResult interface and the callback functionality (which takes advantage of the threadpool).  The IAsynchResult interface exposes an IsCompleted method which can be used to poll a thread’s status.  Once IsCompleted = TRUE, you can call the event’s EndInvoke method.  However, EndInvoke is a blocking call so you don’t want to call it unless you’re sure that job is done.  The most elegant method of handling the check of return results is to define an AsynchDelegate (type AsynchCallback) to do the checking for you. 

A great question was asked by the group – what happens if the event you are calling on a different thread throws an exception?  How do you inform your main thread?  This question is left as an exercise for the reader!  We didn’t have time in the group to really explore the issue.

Positive feedback all around – everyone though the topic was fantastic and that D was a great presenter.  In fact, if she ever comes back to Atlanta, we’d love to have her back to present another topic.  She told us she’s got a great presentation on design patterns.  Maybe I’ll be able to get this presentation from her and let the group  work with it on their own time.

Thank you to everyone who showed up and thank you to both Venkat and Dhamayanthi for presenting!

— Matt Ranlett

posted with BlogJet

 

5/17/2005 12:08:22 PM (Eastern Standard Time, UTC-05:00)  #    Trackback
 Monday, May 16, 2005

Today, for the Atlanta Mobility User Group, I managed to acquire 50 samosas as a snack.  25 vegetable and 25 chicken samosas feed 16 people with only 10 left over at the end.  A lot of the people at the meeting had no idea what they were eating, but I didn't hear a single complaint about the food.  In fact, I think everyone liked what they had!  And what's not to like about a fried pastry stuffed with potatoes, peas, spices, and in some cases chicken?  Even the spicey tamarind sauce we had to go with them was delicious.

So if you're interested in acquiring some of these samosas yourself, go to the India Market at 3547 Old Norcorss Rd, Suite E, Duluth GA 30096.  The people there are really nice and the samosa are $1.00 apiece.  The proprietors are quick to point out that they have lots of great sweets as well as a large selection of vegetarian and ethnic foods.  I can only vouch for the samosas, but I'll be returning to try out the other things they've got to offer.

-- Matt Ranlett

5/16/2005 11:59:56 PM (Eastern Standard Time, UTC-05:00)  #    Trackback
 Tuesday, March 22, 2005

We had a great turn out for the Mobility group, but had a rocky start.  It was a cold winter day, ok so it wasn’t winter and it wasn’t really cold, but Matt and Michael were not able to make it.  They both had circumstances beyond their control, so I went ahead and ran the show. 

 

We had a great time learning about Mobility development for Pocket PC and had some great hands on demos.  The first presentation was a great introduction to the problems of the current CF.NET Framework and some of the “missing” features.  Venkat showed us how to add context menus for Cut and Paste to TextBoxes.  He showed how OpenNETCF has implemented a lot of the “missing” features for Compact Framework.  After a quick demo and showing the code required to make this work, we had our second presenter Kirk Evans come up.  He claimed he was going to show the new “missing” features that CF.NET 2.0 will be adding and the enhancements that will make it worth checking out.  If you are a mobility programmer and want to know what is coming in the next version you should have been at this meeting, I think they will post the slides on the Mobility site.  Kirk went over what is coming in Visual Studio 2005 and showed some of new IDE features like being able to skin your app for the device you are using (cool).  Even though Kirk was not feeling well he managed to give a great presentation that he claims he could do in his sleep.  My guess is that he is that smart and probably could. 

 

Once all the questions had finished we gave away some great prizes that Kirk had brought for us.  Also we had someone announce a position for a Mobility programmer and if you are interested send the Mobility leaders an email and they will put you in contact with him.

--Brendon Schwartz

 

 

update ******

Great post about the first presentation and source code

http://vpolisetti.blogspirit.com/archive/2005/03/24/enable_contextmenus_automatically_for_opennetcf_textboxex_co.html

3/22/2005 11:44:08 AM (Eastern Standard Time, UTC-05:00)  #    Trackback