Wednesday, May 25, 2011

What's new for Developers in Mango (and RIP .NET CF)

TechEd 2011 made me reminisce about my old frienemy the .NET Compact Framework. I will eulogize: Friends and fellow developers, we are here today to pay tribute to our friend of almost 10 years. We were coached, pushed, begged, and commanded to embrace you as you made life so much better for us. Yes, we had to be convinced of that, and we hated you at first. You could not go out without a healthy dose of p/invokes, work-arounds, and patches, but we managed to somehow embrace you as your capabilities grew. Now, you are gone. Plucked from us without notice.

I feel almost as sorry for CF as I did for myself after Microsoft threw its mobile developers under the bus last year when we were told there was no upgrade path from Windows Mobile to Windows Phone 7 (WP7). After stewing on this new direction last year, I have finally come to the conclusion that the abandonment of Window Mobile was actually a good thing. No, I have not embraced WP7. I had never seen another Windows Phone in the wild until I when to TechEd 2011 in Atlanta (and I have had my Samsung Focus since November 2010). Needless to say, the popularity of WP7 is so low it would be risky to venture off in that direction at this time. I am sure others feel the same way. One session at the conference said the ComScores for March 2011 placed Windows Mobile 6 together with WP7 at a 7.5% share of the smartphones in the US (and that is a total of 72.5 million smartphone users). Just for comparison, Android was 34.7%, RIM was 27.1%, and Apple was 25.5%. Since probably half of Microsoft’s 7.5% share is Windows Mobile, that leaves a paltry base of users to target (close to the Palm share of 2.8%). How many palm apps are people writing today? Now, you may ask why I think Microsoft’s throwing its mobile developers under the bus is a good thing. Well, it forced me to go develop for Android, BlackBerry, and iOS. I have traded my less than 7.5% Microsoft base for a 87.3% base. I may one day consider WP7 for my applications, but not today. The moral of the story for Microsoft is that if you tell your developers that they are going to have to rewrite their applications from scratch to run on the new version of the platform, they might spend those resources rewriting their apps for another platform (like Android). This business pattern is unfortunately pretty common (look at Intergraph’s upgrade from FRAMME to G/Technology).

Compiled from various sessions at TechEd, I will run down the list of the major new features Windows Phone will include for developers in its next released (called Mango):

  • Currently, the development platform is a subset of Silverlight 3 or a subset of XNA. The Silverlight 3 subset is being upgraded to a Silverlight 4 subset. There was also talk of blending Silverlight and XNA together to overcome problems in each. This blending will be at a page level (mixing Silverlight and XNA pages together in the same app) and at an element level (putting Silverlight elements on a XNA page, such as text). Regardless, it seems like a crazy mash up on many different levels.
  • From the Silverlight 4 upgrade, new features will include: implicit styles, data binding enhancements, and ICommand support.
  • New interfaces will be available for the camera. This feature should finally overcome one of my biggest complaints with WP7, my QR Code scanner app is pretty much useless when you have to take a picture instead of just “scanning”. Why wasn’t this in the first version?
  • A new Read-only Rich Text Box.
  • Clipboard API.
  • Tap, Double Tap, and Hold Events for Text Box.
  • Red Squiqqlies for misspelled words in a Text Box.
  • Support for Sockets which fills another big hole in the current version.
  • Video Brush so you can draw video on a page.
  • Live Tiles get a new API that allows them to be more accessible and provides new features like text on the Back of a Tile (these tiles flip over periodically to show what is on the back). Single apps can now have multiple tiles and the tiles can deep link to a specific page in the app. App can also control the pinning and unpinning of the tiles from the start page. Also, push notification can happen every 15 minutes instead of an hour, and there can now be 30 push notification endpoints instead of 15. There is supposed to be support for animation like the Xbox Live and People tiles too.
  • Push Notification Toast can Deep Link to pages in an app too.
  • There is supposed to be some multitasking and background processing too, but I wasn’t too clear on what this would be. Not having apps like Twitter or IM clients running in the background in the current version really kills the phone’s usefulness for most people.

Beyond the new features for Developers, Mango will also have the following enhancements:
  • Windows Phone 7 apps will run in a special mode to keep them compatible with the new version.
  • 32 BPP support for images, but defaults to 16 BPP. This feature can be used to fix banding problems with gradient shading (at the expense of performance).
  • Improved battery usage for Video Player which will now draw at ¾ size and scales up (with restrictions like must be right aligned)
  • Input thread introduced in ListBox to improve scrolling.
  • Improvements to memory management that will reduce memory usage in an app by 20 to 30%.
  • Off-thread Image decoding will allow ListBoxes with images to display and then fill in the images without hanging up.
  • Internet Explorer will be upgraded to IE9.
  • Rendering and Input for all languages will be supported.

Personally, I really like my Windows Phone as a phone. I find it unfortunate that it is too unpopular to invest any resources into developing apps for it. I think the Mango update will certainly help overcome its faults and maybe Nokia will eventually disseminate enough of these phones that their share of the market will be worthwhile. However, realigning development efforts to match the smartphone marketshare is unfortunately more urgent than waiting for Microsoft’s platform to come up to speed.

Tuesday, February 22, 2011

Center a Control on a Form in .NET

It turns out to be very easy to center a control on a .NET form. Just un-anchor the control from any side and it will center from its position. If you just un-anchor from the left and right it will center horizontally, and if you just un-anchor from the top and bottom, it will center vertically. Un-anchor from all sides and it will center on the form.

More info at:

http://stackoverflow.com/questions/491399/c-centering-controls-within-a-form-in-net-winforms

Friday, February 11, 2011

How solve the Problem of loading a Native DLL when using ASP.NET

I have had the problem of getting ASP.NET to use a Native DLL for years. I have even posted my complaints in a previous post. My quick and dirty solution has been to simply add the path that contains my DLL to the PATH environment variable and the process would find the .dlls that way. However, if you are using a hosted ASP.NET site or have clients that simply will NOT modify the PATH environment variable, the work around does not work. I have finally found the holy grail of information on how to solve this problem. Why I have not found it before I do not know, and I have search with Google for it a hundred times.

Here is the post I found:

http://blogs.msdn.com/b/jorman/archive/2007/08/31/loading-c-assemblies-in-asp-net.aspx


For ASP.NET, the solution is very simple and elegant. I copy it directly from Jerry Orman's excellent post:

In web.config, add the following…use a path where the Native C++ DLL is located:
<appsettings><add key="NativePath" value="C:\MyNativeDLLs"> </add>

In global.asax, add the following:

protected void Application_Start(object sender, EventArgs e){
String _path = String.Concat(System.Environment.GetEnvironmentVariable("PATH"), ";", ConfigurationSettings.AppSettings["NativePath"]);
System.Environment.SetEnvironmentVariable("PATH", _path, EnvironmentVariableTarget.Process);
}


This post also details other ways of solving the problem as well.

Wednesday, December 1, 2010

Reading App Settings from the Web.Config

For a Web Service that needs to read information form the web.config file (in its own virtual directory), the following is all you need to read the information:

using System.Configuration;
.
.
.
String value = ConfigurationManager.AppSettings["Param_1"].ToString();


The web.config file would contains something like this:











For more information, go to the following links:

http://www.dotnetfunda.com/articles/article13.aspx

The following link show how to read the root web.config file instead of the one in the virtual directory:

http://msdn.microsoft.com/en-us/library/610xe886.aspx

Wednesday, August 25, 2010

Creating Fixed Spaced Fonts for .NET

How to create a fixed space (mono spaced) font for .NET:

Dim f as Font = new Font(FontFamily.GenericMonospace, 12)

Monday, June 14, 2010

Windows Phone 7 - The Haves and the Have-Nots

While Windows Phone 7 (WP7) sounds intriguing as a platform for iPhone-type applications, TechEd 2010 was very illuminating on the many things that this new platform does not include and why you will unlikely be able to migrate your existing Windows Mobile applications forward. Let me go through the laundry list of the have-nots:

  • No native code support. Silverlight 3.0 and XNA are the only ways to develop applications for WP7. If you are not developing games, then Silverlight is probably the path you will be forced to take.
  • No Database support. SQL Server Compact is not part of WP7. Nor will SQLite or any other 3rd party database engine run either. One TechEd session had the gall to suggest that we should all use collections of objects and Linq as a replacement for SQL Server Compact. Access to data is only available through Web Services and what the application can store in Silverlight’s Isolated Storage. No one would confirm or deny that database support would ever be added to WP7.
  • No Side Loading Applications. Except for development mode, applications can only be loaded to WP7 devices through the Microsoft Marketplace. It doesn’t matter if the app if for internal use in your organization or not. Also, it is not free to use the Microsoft Marketplace.
  • Application approval is required. Microsoft claims that it will not be a blackbox like Apple where you stick an app in and hope it comes out; however, they also said they there is a list of applications types that will not be allowed. VOIP was they only example provided.

  • No access to data on SD cards. Since Silverlight applications can only use isolated storage, there is no way for an application to access information on an SD card. While some devices may support an SD card, the additional memory will apparently be made available for isolated storage, but you can’t preload the content.
  • No File System support. Again only Isolated Storage is available to a Silverlight app.

  • No RAPI support. There will no interacting with a WP7 device via the desktop. Obviously there will be some synchronization with Outlook, but nothing the developer will have control of.

  • Applications must be Silverlight 3. Silverlight 4 will not be available for WP7.

  • Out of Browser Silverlight support only. Silverlight is not going to be supported in browser on the phone.

  • Default Browser must be Internet Explorer. While Microsoft claimed that other browsers will be allowed on the phone, they can’t be the default. This is probably okay as long as the new Internet Explorer is better than the Windows Mobile version; however, is it possible to write a viable browser in Silverlight or XNA?

  • No Bluetooth API. While there is going to be Bluetooth support on the phone, there is no Bluetooth API.

  • No inter-process communications (IPC) and no Socket support.

  • No Video Capture Support. Phones will have a camera but not video capture support, and also no video brush.

  • No Outside TrueType Fonts - Microsoft experts claimed that you will not be able to use TrueType fonts other than the ones delivered with the device. This limitation makes since, how would you get them on the device. While there is supposed to be support for embedding TrueType fonts in your xap file in Silverlight 4, this will not be the version used on the device.
  • The TechEd demos of WP7 applications had a common theme; they crashed, hung up, or gave peculiar error messages. For a platform that is going to be delivered in the October timeframe (3 months away), it is hard to have much short-term faith in the new platform.

On the positive side, the list is not quite as long:
  • The Silverlight apps running on the phones looked good even if they were only Silverlight 3.
  • Lots of different soft input panels (SIPs) provided like numeric, URL, email, etc.
  • Built-in support and APIs for multi-touch, accelerometers, vibrator, microphone, and camera.

  • Phones are not going to be feature locked like Windows Mobiles. They should be upgradable like the iPhone.
  • Applications on the phones do not have the strange isolated storage limits that desktop Silverlight applications have.

Microsoft continually offered up that they were so rushed to get this phone to market that they had to leave a lot of things out. Since the phones are not feature locked (so they claim), maybe there will be a quick release cycle of new versions to fill in the missing components. If you are not planning on developing iPhone type applications (casual games or casual apps usually requiring a connection to a backend), you may be stuck waiting for a new release will new features (or jumping ship to Android or the iPhone). The WP7 platform as it is depicted today will not be able to support the sophisticated applications that are currently running on Windows Mobile, so it cannot be thought of as a successor to the Window Mobile platform. There are many new and great things you can do on WP7, but this constitutes a different kind of platform (one to compete with the iPhone). Will it grow to be a successor to Windows Mobile? How long will this take? What if it flops against the iPhone and never takes hold? Too many questions around the platform to invest a significant amount of development into it if you are not focused on creating iPhone type apps.

***** Since I posted this blog entry, I went to another TechEd and wrote another more updated post.

Wednesday, June 2, 2010

Preventing Tabs from being Selected

I tried several solutions I found on the internet to prevent tabs from being selected with a TabControl, but the link below shows the only solution that worked well. My task was very simple, I didn't want the user to select other tabs until the first tab contained valid information. The trick was to use the Deselecting event on the TabControl. In the event, see which tab you are on (SelectedIndex) and perform your validation specific to the tab. If the validation fails, set the event's e.Cancel to True and the tab won't change.

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Studio_.NET_2005/Q_23411323.html