An Original Idea

because all great software begins with an original idea

Silverlight 3 style NavigationContext in WPF

Posted by anoriginalidea on July 8, 2009

 image

At the moment I’m experimenting with various user interface technologies.  Because the prototypes are working in parallel, I want to reuse code where possible.  With this in mind, I’ve created a couple of useful wrapper functions for navigation in both Silveright 3 and WPF that I thought I’d share.

 

In case you don’t know the Silverlight 3 Beta now has a navigation framework that works in a similar way to WPF’s Frame navigation feature.   To learn more about it, check our Jeff Poise’s great article Silverlight 3’s New Navigation Framework.

 

I brief, to navigate to a new page and pass a parameters you use a syntax like this in the code behind:

 

Me.NavigationService.Navigate(New Uri(String.Format(“/SomePage.xaml?someparameter={0}”,somevalue), UriKind.Relative))

 

In the loaded event of the page you’re navigating to, you use code like this:

 

Private Sub MyPage_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
     txtSomeTextbox.Text =  Me.NavigationContext.QueryString("someparameter")
End Sub

 

Nicer Navigating

I found the Navigate method above a little awkward, so in Silverlight I created a little helper function called “NavigateTo”, on page that makes the code a bit nicer.

 

Me.NavigateTo(“/SomePage.xaml”,”someparameter”,somevalue)

 

Here’s the implementation:

 

Imports System.ComponentModel
Public Module PageHelper
    <System.Runtime.CompilerServices.Extension()> _
   Public Sub NavigateTo(ByVal page As System.Windows.Controls.Page, ByVal navigationUrl As String, ByVal ParamArray arguments() As String)
        Dim lsUrl As String = navigationUrl & "?"
        Dim lbIsParamName As Boolean = True
        For Each lsArg As String In arguments
            lsUrl &= lsArg
            If lbIsParamName Then lsUrl &= "="
            lbIsParamName = Not lbIsParamName
        Next

        page.NavigationService.Navigate(New Uri(lsUrl, UriKind.Relative))
    End Sub

End Module

 

Nicer NavigationContext

 

I found Silverlight3’s NavigationContext quite nice to use.  Unfortunately this is not available in WPF.  I set about creating a helper function that would emulate this functionality in WPF.

 

WPF Navigation Helper

 

Here’s a WPF version of PageHelper that allows a compatible syntax with Silverlight3.  

 

Imports System.ComponentModel
Public Module PageHelper

    Private WithEvents moCurrentNav As NavigationService
    <System.Runtime.CompilerServices.Extension()> _
   Public Sub NavigateTo(ByVal page As System.Windows.Controls.Page, ByVal navigationUrl As String, ByVal ParamArray arguments() As String)

        '  Update Navigation Args
        Dim loNavigationUri As New NavigationContext

  If arguments.Length > 0 Then
            For i As Integer = 0 To arguments.Length - 1 Step 2
                 loNavigationUri.QueryString.Add(arguments(i), arguments(i + 1))
            Next

            End If

           
        loNavigationUri.Uri = New Uri(navigationUrl, UriKind.Relative)

        ' Strip the Xaml extension 
        Dim lsClassName As String = navigationUrl.Substring(0, navigationUrl.Length - 5) 
        ' Make my class name 
         Dim lsName As String = page.GetType.Namespace & "." & lsClassName 
        ' Instantiate the class 
        Dim loPage As Page = page.GetType.Assembly.CreateInstance(lsName) 
        ' Do the Navigation 
         page.NavigationService.Navigate(loPage, loNavigationUri)
    

        ' Store the current NavigationService so we can complete
        moCurrentNav = page.NavigationService

    End Sub
    <System.Runtime.CompilerServices.Extension()> _
Public Function NavigationContext(ByVal page As System.Windows.Controls.Page) As NavigationContext
        Return moLastNavContext
    End Function
    Private Sub moCurrentNav_Navigated(ByVal sender As Object, ByVal e As System.Windows.Navigation.NavigationEventArgs) Handles moCurrentNav.Navigated
        moLastNavContext = e.ExtraData
        moCurrentNav = Nothing
    End Sub
    Private moLastNavContext As New NavigationContext

End Module
Public Class NavigationContext
    Public QueryString As New Dictionary(Of String, String)
    Public Uri As Uri
End Class

 

I also have provided primitive support for cross-assembly navigation.

 

I hope someone found this useful, let me know.

 

 


Share this post :

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Posted in Silverlight, Windows Presentation Foundation | Tagged: , , | Leave a Comment »

Silverlight “Name ‘InitializeComponent’ is not declared”

Posted by anoriginalidea on July 1, 2009

She'd be far less frutrated if she plugged it into the network first.

It is quite common in Webforms, Winforms and other environements to copy user interface views from one project to another.

When you copy xaml files from one Silverlight project to another you may experience the error:

“Name ‘InitializeComponent’ is not declared”

 

This happens because the “x:Class” directive in the top of the xaml file includes the project namespace.

So, open up your xaml file, and change this:

 

x:Class=”PreviousProject.YourClass”

 

To the new project namespace:

x:Class=”NewProject.YourClass”

 

Oh and BTW…..ITS CASE SENSITIVE! 

 

I know this isn’t much of a post, but hopefully it will provide a useful search engine hit for the desperate.

Posted in Silverlight | Tagged: , | Leave a Comment »

Reflections on Permutation City

Posted by anoriginalidea on April 15, 2009

Permutation City

 

Imagine a world where your a copy of your consciousness could be downloaded into a supercomputer, where you continue to exist, running as another computer program.   A Virtual World is provided for your “Copy” to exist in.

Although Copies only run at one seventeenth of the speed (at most) of “real” humans, they don’t notice, as from their point of view, time seems normal. 

The Copy itself made up of a brain and a body.  The brain is a software simulation of the neural network of the brain, which provides a copy of the consciousness with full fidelity.  The “body” is made up of a number of less sophisticated simulations of various organs.

The way a Copy actually “thinks” is not fully understood.  Nevertheless it is possible for the Copy to alter it’s world, body, memories and emotions.

The ability to dull or intensify specific emotions is a key driver of life.  We continue to seek happiness, thrills and highs whilst trying to alleviate suffering, unpleasantness and guilt.

In our society this is done using both external and internal stimulus.  The use of alcohol and drugs (or the iPhone) in our society provide many with a quick (although temporary) fix, others follow a seemingly endless variety of ideas, philosophies, sciences and religions.

In the book “Permutation City”, by Greg Egan, the idea of “Copies” began in medicine, where medical researchers were creating increasingly sophisticated software models of the brain and body.  A breakthrough occurred when a researcher was able to activate the consciousness of a scan of himself and place it in a primitive VR environment.  It’s first words were “Please let me out! This feels like being buried alive.”  Despite this (as it turns out common) reaction, copies became an attempt at designer immortality, with very interesting repercussions.

The book is full of great ideas and was a really interesting read.

Posted in Book Review | 1 Comment »

Why my brain hurts – Objective C vs VB.Net

Posted by anoriginalidea on March 11, 2009

It has been said that software developers can expand their skills by learning a new computer language a year.  The similarity of languages I have encountered up to this point led me to doubt whether this was so.  I was wrong.

In my quest to create the ultimate iPhone application, I’ve had to learn not only a new platform but a whole new computer language, “Objective C”.  My “native” computer language is C, so imagine my consternation when found how different Objective C appears from C Sharp and C++.

So far there doesn’t seem to be any direct comparison between .net languages and Objective C, so I thought I’d post a small article on the subject.  I have decided to use VB.Net as the basis of comparison, but I’m sure C Sharp developers can understand the concepts.   This article is based on the fine Wikipedia introduction to Objective C.  I encourage you to take a look at this.

 

 

Method Invocation and Method Passing

To invoke a method on an Objective C object, we “pass a message”.  This differs from VB.Net in that a method must exist in order to invoke it.

Declaration of classes, by convention are done in two seperate files, a “.h” header file containing an interface declaration and a “.m” (method implementation) containing the actual class code.

HelloWorld.h

@interface HelloWorld : object 

- (id) hello;

@end

 

HelloWorld.m

 

#import “HelloWorld.h”

 

@implementation HelloWorld

- (id) hello

{

   printf(”Hello World”);

}

 

To use this class:

HelloWorld * myhello = [[HelloWorld alloc] init];

[myhello hello];

 

A rough VB.Net equivalent might be:

 

Public Class HelloWorld

   Public Sub Hello

        Console.WriteLn(”Hello World”)

   End Sub

End Class

 

Invoked by:

 

Dim myhello As New HelloWorld

myhello.hello

 

 

A big difference between these examples, is that in the Objective C case, the hello method does NOT have to be implemented at all.  It’s only responding to a “message” that the class may or may not have an implementation for.

 

Admittedly this does produce a compiler warning “warning:’HelloWorld’ may not respond to ‘-hello’”, but it still compiles.

 

A better VB.Net equivalent may be the use of reflection to check for the existence of a method prior to invocation:

 

Dim myhello As New HelloWorld

If myHello.GetType.GetPropInfo(”Hello”) IsNot Nothing Then myHello.hello

 

Another way would be to treat the object as an “object”.  For example:

Dim myhello As New HelloWorld

Ctype(myhello,object).Hello

 

That’s probably missing the point however, because it effectively causes an error at runtime, whereas ObjectiveC does not produce an error.

 

Another possible VB.Net equivalent could be using Events.  Are these equivalent to messages?

 

Public Class HelloWorld

   Private WithEvents moHelloWorldEventSource As HelloWorldEvents 

   Public Sub New(eventSource As HelloWorldEvents)

        moHelloWorldEventSource = eventSource

   End Sub

 

   Private Sub Hello Handles moHelloWorldEventSource.Hello

        Console.WriteLn(”Hello World”)

   End Sub

End Class

Public Class HelloWorldEventSource

      Public Event Hello

      Public Sub Hello

           RaiseEvent Hello

      End Sub

End Class

 

To invoke this masterpiece:

 

Dim helloEvents As New HelloWorldEventSource

Dim myhello As New HelloWorld(helloEvents)

helloEvents.Hello

 

 

Another capability of Objective C is to pass an unhandled method invocation to another object.  VB.Net does not seem to have an equivalent of this.

 

Protocols (Interfaces)

 

Protocols introduce the multiple inheritance of specification, but not implementation through the introduction of “protocols”.

 

Our Objective C hello world class could implement a prototcol:

 

@protocol DescribeDialect

- (void)DescribeYourLanguage;

@end

 

 Like this:

 

@interface HelloWorld : Object <DescribeDialect>

….

@end

 

I get the impression that although HelloWorld declares it implements the DescribeDialect protocol, I’m not sure if it really has to implement each of the methods.  I’m guessing it should.

 

The vb.net equivalent is quite direct:

Public Interface DescribeDialect

    Sub DescribeYourLanguage

End Interface

 

Public Class HelloWorld

     Implements HelloWorld

….

End Class

 

The only element of confusion here is the use of the word “interface” between the languages.  I suppose knowing “protocol” exists helps with this.

 

Dynamic Typing

A programming language is said to be dynamically typed when the majority of it’s type checking is performed at runtime as opposed to compile time.

 

The previously described “optional” implementation of a passed message allows for increased flexibility.  See “Forwarding” for more information.

 

Static typing information may also be added to variables.  The information is then checked at compile time.

 

For example:

 

- setMyValue:(id) foo;

- setMyValue:(id <aProtocol>) foo;

- setMyValue:(NSNumber*)foo;

 

The vb equivalent appears to be declarations with multiple signatures, like this:

 

Public Sub setMyValue(foo As object)

End Sub

Public Sub setMyValue(foo As DescribeDialect)

End Sub

Public Sub setMyValue(foo As String)

End Sub

 

Post Java 1.5 and the .net languages also support “generics”.  I am unsure at this stage if Objective C supports this or not.

 

Forwarding (Delegation)

Since Objective-C permits the sending of a message to an object which might not respond to it, the object has a number of things it can do with the message. One of these things could be to forward the message on to an object which can respond to it. Forwarding can be used to implement certain design patterns, such as the Observer pattern or the Proxy pattern very simply.

There is no direct VB.Net equivalent of this behaviour.  See the wikipedia article for more information.

Categories

In VB.Net 9, a new feature called “Extension Methods” allowed the creation of extra methods on sealed classes.  Objective C’s “categories” are a similar way of creating groupings of methods in separate files that  allow the extension of a base class at runtime.

If we wanted to extend the HelloWorld class above to have an extra Goodbye method, in Objective C we could write:

 

HelloWorldGoodbyes.h

 

#import “HelloWorld.h”

 

@interface HelloWorldDisplay  (HelloWorld) 

- (id) goodbye;

@end

 

HelloWorldGoodbyes.m

 

#import “HelloWorld.h”

 

@implementation HelloWorld

- (id) goodbye

{

   printf(”Bye”);

}

 

The VB.Net equivalent using extension methods could be:

 

Imports System.Runtime.CompilerServices

Module HelloWorldDisplay

 

      <Extension()>Public Sub goodbye(Byval targetHelloWorld As HelloWorld)

               Console.WriteLn(”Bye”)

      End Sub

 

End Module

 

 

A similar VB.Net feature is “partial” classes, although these are compile time constructs.

 

Partial Public Class HelloWorld

   Public Sub Hello

        Console.WriteLn(”Hello World”)

   End Sub

End Class

 

Partial Public Class HelloWorld

   Public Sub Goodbye

        Console.WriteLn(”Bye”)

   End Sub

End Class

 

I don’t believe either of these equivalents support Objective C’s ability to override the base implementation.

 

Posing

Class Posing is an Objective C feature that allows messages sent to the target class to be wholy replaced by calls to a substitute class with the same implementation.

A class may only pose as one of its direct or indirect superclasses

  • The posing class must not define any new instance variables which are absent from the target class (though it may define or override methods).
  • The target class may not have received any messages prior to the posing.

Posing, similarly to categories, allows globally augmenting existing classes. Posing permits two features absent from categories:

  • A posing class can call overridden methods through super, thus incorporating the implementation of the target class.
  • A posing class can override methods defined in categories.

 

Here’s an example:

 

@interface CustomNSApplication : NSApplication

@end

 

@implementation CustomNSApplication

- (void) setMainMenu: (NSMenu*) menu

{

     // do something with menu

}

@end

 

class_poseAs ([CustomNSApplication class], [NSApplication class]);

 

There is no direct VB.Net equivalent of this functionality.  Similar constructs may be created by implementing a singleton pattern combined with an interface.

 

It appears that this feature has been “depreciated” in MacOS 10.5 and onward, so I wont dedicate discuss it any further.

 

#import

 

The #import directive is similar to the #include directive in C, except it only includes a nested file once.   In VB.Net files in the same “project” are automatically included together in this way.

 

If the developer decides to structure their code with namespaces, the VB.Net “Imports” keyword allows inclusion of namespaced classes without having to prefix the namespace path.

And so ends our brief comparison of the two languages.  If you’re after a comparative critique, I am sorry to disappoint you.  Each language has it’s strengths and weaknesses.  At the moment I’m not qualified to comment either way.

If you found this useful, feel free to leave a comment.

 

Links

Posted in Objective C, VB.Net | 1 Comment »

Catching Application Level Mouse Events in Winforms

Posted by anoriginalidea on February 23, 2009

image

As part of my work on flick scrolling I’ve created an example of a class that can create mouse events for an entire Winforms application.

To use it, just declare it, like so:

Private WithEvents moAppMouseEvents As New ApplicationLevelMouseEvent

 

I’ve only implemented the MouseUp and MouseDown events, but these are consistent with the Form ones:

 

Private Sub moAppMouseEvents_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles moAppMouseEvents.MouseUp

 
End Sub
Private Sub moAppMouseEvents_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles moAppMouseEvents.MouseDown
 
End Sub

 

The code uses an IMessageFilter in the tradtional fashion:

 

Public Class ApplicationLevelMouseEvents
    Implements IDisposable
    Implements IMessageFilter

    Public Event MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)
    Public Event MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs)

    Private Const WM_LBUTTONUP As Integer = &H202
    Private Const WM_LBUTTONDOWN As Integer = &H201
    'Private Const WM_RBUTTONDOWN As Integer = &H204
    'Private Const WM_MBUTTONDOWN As Integer = &H207
    'Private Const WM_NCLBUTTONDOWN As Integer = &HA1
    'Private Const WM_NCRBUTTONDOWN As Integer = &HA4
    'Private Const WM_NCMBUTTONDOWN As Integer = &HA7
    Public Sub New()
        Application.AddMessageFilter(Me)
    End Sub

    Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) As Boolean Implements System.Windows.Forms.IMessageFilter.PreFilterMessage
        If (m.Msg = WM_LBUTTONDOWN) Then

            Dim loArgs As New MouseEventArgs(MouseButtons.Left, 1, System.Windows.Forms.Cursor.Position.X, System.Windows.Forms.Cursor.Position.Y, 0)

            RaiseEvent MouseDown(Me, loArgs)

        ElseIf (m.Msg = WM_LBUTTONUP) Then
            Dim loArgs As New MouseEventArgs(MouseButtons.Left, 1, System.Windows.Forms.Cursor.Position.X, System.Windows.Forms.Cursor.Position.Y, 0)
            RaiseEvent MouseUp(Me, loArgs)
        End If
        Debug.WriteLine(m.Msg.ToString)
        Return False

    End Function

    Private disposedValue As Boolean = False        ' To detect redundant calls

    ' IDisposable
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
                Application.RemoveMessageFilter(Me)
            End If
        End If
        Me.disposedValue = True
    End Sub

#Region " IDisposable Support "
    ' This code added by Visual Basic to correctly implement the disposable pattern.
    Public Sub Dispose() Implements IDisposable.Dispose
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub
#End Region

End Class

 

The sample could be enhanced to support the full range of events such as mouse move, so feel free to take the sample and change it.  If you post your code, please link back to this post.

 

Links

A Simple Scroll Controller for Winforms

Posted in Uncategorized | 2 Comments »

A Simple Scroll Controller for Winforms

Posted by anoriginalidea on February 20, 2009

 image

I am currently researching “flick” scrolling for Windows XP and over.  As part of this I need the ability to scroll controls in code.

To do this I have created a wrapper around the scrolling apis to assist with this.

Here’s how to use it for an autoscrolling panel:

 

Dim loScrollIt As New ScrollController(Panel1)

loScrollIt.VerticalScroll(20)

 

Here’s the code:

Imports System.Runtime.InteropServices
Public Class ScrollController

    ' Scrollbar direction
    '
    Const SBS_HORZ = 0
    Const SBS_VERT = 1

    ' Windows Messages
    '
    Const WM_VSCROLL = &H115
    Const WM_HSCROLL = &H114
    Const SB_THUMBPOSITION = 4

    Private Declare Function GetScrollPos Lib "user32.dll" ( _
        ByVal hWnd As IntPtr, _
        ByVal nBar As Integer) As Integer

    'Example: position = GetScrollPos(textbox1.handle, SBS_HORZ)
    Private Declare Function SetScrollPos Lib "user32.dll" ( _
        ByVal hWnd As IntPtr, _
        ByVal nBar As Integer, _
        ByVal nPos As Integer, _
        ByVal bRedraw As Boolean) As Integer

    'Example: SetScrollPos(hWnd, SBS_HORZ, position, True

    Private Declare Function PostMessageA Lib "user32.dll" ( _
        ByVal hwnd As IntPtr, _
        ByVal wMsg As Integer, _
        ByVal wParam As Integer, _
        ByVal lParam As Integer) As Boolean

    'Example: PostMessageA(hWnd, WM_HSCROLL, SB_THUMBPOSITION _
    '                         + &H10000 * position, Nothing)

    Private moControl As Control

    Public Sub New(ByVal controlToScroll As Control)

        moControl = controlToScroll
    End Sub
    Public Sub VerticalScroll(ByVal amount As Integer)
        Dim liHwnd As IntPtr = moControl.Handle
        Dim Position = GetScrollPos(liHwnd, SBS_VERT) + amount

        If (SetScrollPos(liHwnd, SBS_VERT, Position, True) <> -1) Then

            PostMessageA(liHwnd, WM_VSCROLL, SB_THUMBPOSITION + _
                                       &H10000 * Position, Nothing)
        End If

    End Sub

End Class

Posted in .net Framework, Code, Software Development, VB.Net | 1 Comment »

More VSTO fun : WindowActivate in Outlook/Word 2007 does not fire for Wordmail more than once

Posted by anoriginalidea on February 9, 2009

image

Welcome to the horrible world of creating Outlook addins that work for both 2003 and 2007.

People have commented that wordmail has a horrible side effect in Word 2003, where toolbars used in Outlook inspectors show up in Word.  See the this Kevin Slovak’s discussion of the problem in the links section.

Anyway, the workaround mentioned in the article doesn’t work (of course) in Outlook 2007.  It is therefore necessary to check the version of Word (which doesn’t have toolbars) for the code to work for both versions.

It makes me wish Microsoft would hand out free office upgrades.

Anyway, here’s the complete code:

 

' Listen for inspector activate
Private WithEvents moWord As Microsoft.Office.Interop.Word.Application
Private moInspector As Inspector
Private Sub moWord_WindowActivate(ByVal Doc As Microsoft.Office.Interop.Word.Document, ByVal Wn As Microsoft.Office.Interop.Word.Window) Handles moWord.WindowActivate

     If Wn.EnvelopeVisible AndAlso moInspector IsNot Nothing Then
         mShowInspector(moInspector)
         moInspector = Nothing
         moWord = Nothing
         If Doc.AttachedTemplate IsNot Nothing Then Doc.AttachedTemplate.Saved = True
     End If

End Sub
Private Sub moInspectors_NewInspector(ByVal Inspector As Microsoft.Office.Interop.Outlook.Inspector) Handles moInspectors.NewInspector

     Dim lbRaiseEvents As Boolean = True

     If Inspector.IsWordMail Then
         ' HACK: Wordmail does not work in the same way in
         ' Word 2008 as it does in 2003.  I think this
         ' may be because of the lack of real toolbars
         ' in Word 2007.
         If Val(Inspector.WordEditor.Application.Version) < 12 Then
             moInspector = Inspector
             moWord = Inspector.WordEditor.Application
             lbRaiseEvents = False
         End If
     End If
     If lbRaiseEvents Then mShowInspector(Inspector)

End Sub

 

This code is provided in case some poor soul out there gets the problem as well. 

 

Links

Problem with Inspector CommandBars and MS Word [WiredBox.Net - Office Newsgroups]

Inspector Wrapper for Wordmail VSTO and vb.net

Posted in .net Framework, Outlook, VSTO | Tagged: , , | Leave a Comment »

Alright, I admit it, Now I have an iPhone!

Posted by anoriginalidea on January 16, 2009

 

Dear Windows Mobile,

 

By the time you read this blog post, I’ll be gone.  I’m sorry for doing this but you left me no other choice.  I know comes as a bit of a shock to you – especially because things have been going so well.  But I’m sorry – I cant stand watching all those iPhone users giggling in the corridors anymore.  I think you’re swell, but I don’t think we’re right for each other.  First of all, we’re not compatible.  You’re a a bit too clunky and I’ve lost patience.   Secondly, I’m tired of waiting for Windows Mobile 7.  It’s too late isn’t it?

Anyway, I want to try another smart phone.  But you know what?  I still want to be friends.  We had some good times, developing software on the brilliant compact framework.  I’m very sad it has to be this way.  But please, don’t cold boot like last time.  Maybe I could still answer questions on the Compact Framework from time to time.  I still code in .net!  Look I wont even make issue of the fact that I had to buy you a replacement battery.

So, take care of yourself and all the best.

Sincerely

Me

Posted in Comedy, Software Development, iPhone | Tagged: , , | 1 Comment »

Musings about the memory usage of WPF and Winforms Applications

Posted by anoriginalidea on November 23, 2008

Newcomers to Winforms and WPF .net applications are sometimes alarmed about the amount of memory they are shown to use in Task Manager.  

When these applications run in a Terminal Server environment (or Citrix) the memory consumption seems to add up.  I have heard of products that somehow reduce the memory consumption of processes in this environment.   The makers of these products claimed to be able to fit more processes on the one server. I made it my mission to find out how these applications may work.

Minimizing as a Lifestyle

A hint as to how they may work is the behaviour of the application when it’s minimised.  Memory usage definitiely goes down.  When the application is normalised, memory consumption goes back up, but not as much.

For example, with a WPF application with a single window and no controls, according to Task Manager uses 27388K.  On minimise of the application, memory consumption goes down to 3128K.  Normalising the application, the memory consumption goes back to 8306K.

Apparently minimizing the application makes a call to the Win32 api call SetWorkingSet, this is what causes the apparent memory reduction.  Looking at the history of Windows, this behaviour makes sense.  In the Windows 3.1 user interface, minimizing applications was the way a user typically indicated to Windows they were switching to something else.

Something I wonder about is whether this is still appropriate?  Since Windows 95 introduced the Task Switcher, do people still minimise?    Another question.  In the Terminal Server environment, is the call being made when a user becomes idle?  Should it be?

SetWorkingSet(-1,-1)

Microsoft’s documentation of the call indicates that application calls to SetWorkingSet are not necessary, as the operating system will manage the memory as required.   Is this automatic memory management assuming the Windows 3.1 usage pattern? 

Two years ago I created a prototype that called SetWorkingSet when an application had become idle for a certain amount of time.  It seemed to work well, but I had no evidence it helped system performance particularly.

I apologise for the inconclusive nature of this post, but I thought I would put my musing out there in case others had anything to comment.

 

Links

Reducing WinForm Memory Footprint with SetWorkingSet

How much memory does my .NET application use?

WPF Memory Usage

 


Share this post :

Posted in .net Framework, Software Development | Tagged: , , , | 1 Comment »

iPhone

Posted by anoriginalidea on November 15, 2008

“In more bad news for Windows Mobile, Apple shipped more iPhones in the quarter than the total of all handsets based on the Microsoft system, even though their numbers actually increased by 42%.” (See article Apple and RIM tussle for Q4 prizes as smartphones boom)

I’m really sorry, but I don’t think Windows Mobile 6.5 or 7 is going to make any difference, it seems that Microsoft is not going to be able to produce anything compelling enough, soon enough.   I don’t think there’s going to be a “comeback”.

In case you think that the iPhone is all hype and marketing, I have a question for you.  Have you ever tried using one?  I have yet to meet anyone who has had less than a “revelatory” experience using an iPhone. 

I’ve had a great experience developing for the platform (I think the Compact Framework is excellent).

I believe the future of mobile computing is and is going to be huge, but I’m afraid Windows Mobile isn’t going to play a significant role anymore. 

Future handset operating systems will be various, including of course the iPhone and Android.

Other mobile devices such as tablet computers and netbooks will probably continue to run Windows, so I think Microsoft should concentrate their efforts on continuing to ensure relevance on this form factor.

For developers I think the news is all good.  There are great opportunities out their in mobility, if we are willing to “move on” in our choice of development technologies. 

 

Links

Permanent Link to IE6 for Windows Mobile – Better, but not brilliant

The Mobile Spoon: What happens when a Windows Mobile Addict breaks his vow and buys an iPhone?

Apple and RIM tussle for Q4 prizes as smartphones boom

 


Share this post :

Posted in .net Framework, Pocket PC Development, Software Development | Leave a Comment »