Category Archives: .Net CF

Adventures of the compact world a.k.a .Net Compact Framework

Oreintation Aware Control Revisited

few days back i have posted about the orientation aware control (OAc) , how much it  is beneficial to the mobile development and other stuf.

well while working with oac i observed that , the resource names generated follow the VS naming convention as they are generated by build process. , and your source code should follow certain heirarchy, otherwise your resources will be named incorrectly. Also OAC expects all the resources to be embeded in the main assembly and file based resources will not be loaded,OAC utilizes Localization feature of .net framework, but overrides the component resrouce manager to look for resource in the main assembly only ,

for my aplication it was more desirable to have resource splitted in to culture base resources, for each resolution. after spending some time with msbuild i found that this is acheivable.

for generating proper resource names i used <LogicalName>myresourcename.resource</LogicalName>

for generating separte setallite assemblies for each resource. i added few build action

<AvailableItemName Include=”EmbeddedResource320_240″ />
<AvailableItemName Include=”EmbeddedResource480_640″ />
<AvailableItemName Include=”EmbeddedResource640_480″ />

then updated build action of each resoultiion related resx to its build type , like abc.320-240.resx , will have build action “EmbeddedResource320_240″ and so on

and then override the After Res Gen build event in my project file

<Target Name=”AfterResGen”>

<CreateItem Include=”@(EmbeddedResource320_240)” AdditionalMetadata=”Culture=320-240″>
<Output TaskParameter=”Include” ItemName=”OACResrouceWithCustomCulture”/>

<CreateItem Include=”@(EmbeddedResource480_640)” AdditionalMetadata=”Culture=480-640″>
<Output TaskParameter=”Include” ItemName=”OACResrouceWithCustomCulture”/>

<CreateItem Include=”@(EmbeddedResource640_480)” AdditionalMetadata=”Culture=640-480″>
<Output TaskParameter=”Include” ItemName=”OACResrouceWithCustomCulture”/>

<Message Text=”@(OACResrouceWithCustomCulture) ” />
<MakeDir Directories=”$(IntermediateOutputPath)%(OACResrouceWithCustomCulture.Culture)”/>
<GenerateResource  Sources=”@(OACResrouceWithCustomCulture)” OutputResources=”@(OACResrouceWithCustomCulture->’$(IntermediateOutputPath)%(LogicalName)’)”>

<Output  TaskParameter=”OutputResources”     ItemName=”OACResrouces”/>
<Output  TaskParameter=”FilesWritten”     ItemName=”FileWrites”/>

<AL EmbedResources=”@(OACResrouces)”
OutputAssembly= “$(IntermediateOutputPath)%(OACResrouces.Culture)\$(TargetName).resources.dll”>

<Output TaskParameter=”OutputAssembly”     ItemName=”OACSatelliteAssemblies”/>


<Copy  SourceFiles=”@(OACSatelliteAssemblies)”

<Output TaskParameter=”DestinationFiles” ItemName=”FileWrites”/>



problem solved :D:D

i dont know the behavour when localizing control with different languages




Orientation Aware Control

Orientation aware control for windows mobile device( windows mobile 5.0) is an outcome from patterns and practice group at microsoft.  now adays mobile deivces support different resoultion and orientation. (i ll refer to Windows mobile 5.0 device simply as devices from now on). the available resolution are 240*320, 640*480, 240*240, 480*480 with portrati and landscape orientation . as with .net compact framework, we can build application to target different devices with with same code base , the problem lies where there are different resolution and orientation  .this was quite cumbersome ,until the orientation aware control was released by Paterrens and practice group as part of mobile client software factory.

u can derive all ur  controls from the orientation aware control ,orientation hooks up with the windows mobile api to get notified when orientation changes,it makes use of Resource localization feature , and creates different custom resource culture for different res /orientation and applying them accordingly.

as most of u people know that VS2005/vs2003 expects certian files to be in certain physcial folder hierarchy . here u can find these naming convention. the generated resources name follow these convention.

so what if ur source code hirerachy is a bit different then expected by VS ,as we have in our current application. Since OAC make heavy use of resources and those resource are getting named as per defualt rules, the OAC does not seem to work properly.:(.

the solution, was to some how instruct the VS to generate the proper name, or to revise the source code herirachy. later was not appropriate since we were going to handover the build to the testing dept after 3 days and this may lead to havoc. so i researched on the first option ,trying to instruct VS , i dwelled within msbuild csproj files, and target files , to get to know how these are generated. and found out that these are generated via task GenerateManifestResourceName. One solution that readily poped up at the moment was to override the task and implement the new behaviour, but that would result in the maintaining a complete custom copy of microsoft msbuild default target files, which may lead to unknow behaviour in case of some updates,
next option was to introduce new Include Type (embeded resource,compile ,content are existing one), i.e. include the new resources as say OACResx , and  write a task to process , and inject the task using BeforeResGen task. that sound quite better, and definitly i was going to implement that but i found  an easeir solution. that is if u want to name ur resource ur way then just insert a tag <LogicalName>ur name goes here </LogicalName> in the Embeded resource node. this wil generate ur desired name, i made heavy use of this feature in my application.

so now OAC is performing great.Althoug i have to edit the  csproj file after creating new control, but thats just one time thing not of much pain. OAC designer should support this kind of thing, i m reviewing their source code for possible changes. will let u know if found something interesting.

.Net Compact Framework Doest Not Support Direct Asynchronous method call.

wel working on .net compact framework, i found that as of version 2.0 sp1,it does not support asynchronous calling from a delegate. what this means is that u will not be to call deleagate.BeginXXX.
this is currently not documented very much in the .net cf documentation. The thing is that when u r working in the VS2005 you wil be able to declare a delegate ‘mydel’ and assigned a reference of function say ‘foo’ to it, now when write ‘mydel.’ intellisense wil list the asynchnrous function call namely ‘BeginFoo’ and ‘EndFunction’ and allows u to complete ur line . the compiler will provide the async functiona call stub , beginxxx, endxxx for function xxx, and ur application compiles successfully , now when u run the application it will throw not method not supported exception
this behaviour is not documented in the .net cf documentation. i observed this while working on my application , which has component that was ported from its desktop counterpart. the behaviour appeared from nowhere during the middle of development, while searching for the possible causes , i found that it is not supported on cf and that was burried in an msdn forum,

althoug asynch calls arent supported but threadpool is available on the cf which can lead to an easy workaround for the scenario, a wrapper class with that will take a delegate, and put its own method to be executed on threadpool , does all state management thing required.
class myClass
delegate mydelegate ;
object state;
public static object CallAsynch(delegate mydel ,object state)
myClass asyn=new myClass();
ThreadPool.QueueUserWorkItem(new AsyncCallbackDelegate(asyncCaller),asyn);

public asyncCaller(object state)


that is just a concept, if u want to return the some values from the function u need to add some more code,