Mobile Line Of Business

Richard Jones (MVP)

  Home  |   Contact  |   Syndication    |   Login
  202 Posts | 0 Stories | 36 Comments | 0 Trackbacks


Welcome to the Mobile Line Of Business Blog

Tag Cloud

Article Categories


Post Categories


So this has taken a bit of investigation.  A customers of ours was reporting duplicate transactions arriving from one of our mobile line of business applications.

After much head scratching, we’ve uncovered something that I’m sure may help others.      Most transactions get fired by the user of the mobile device pressing the right hand soft key i.e :


In most cases pressing this soft key, would perform the action then dismiss the form, usually by just setting the DialogResult of our current form.

To create a good user experience what I often do is immediately on pressing an action button, bring up the wait/spin cursor and disable buttons etc.   to show to the user that cogs are turning and the transaction is being processed.

So what our customer has been observing is that for some reason we were still receiving multiple posts of transactions.

Obviously this is a serious issue.   So how may you ask, could a user press a disabled button repeatedly?

The first thing to look at, was when does the user interface update to disable the button.   Our code looked sensible enough, with the first lines of the menu button soft click event looking like-

private void mnuok_Click(object sender, EventArgs e)
this.mnuok.Enabled = false;
Cursor.Current = Cursors.WaitCursor;

// etc

This ensures that the user interface updates pretty much immediately.

< Much Time passes…. >

OK,  so here’s what we found out.   In an effort to make the user interface faster we had also allowed our end user to press Enter on the keyboard (we are using Motorola MC9090Ks) , and after one of my colleagues drove a two hour round trip (Thanks Ross) we found the issue.

Sure enough our end user was prodding the Enter repeatedly,  and if you look at the KeyDown event for the form the problem becomes obvious -

 private void frminventorymove_KeyDown(object sender, KeyEventArgs e)
            if ((e.KeyCode == System.Windows.Forms.Keys.Enter))
                if (mnuok.Enabled)
                    e.Handled = true;
                    mnuok_Click(sender,null); // call our code

// etc...


So despite all our tidy interface design,  its seems that even though the mobile device was as busy as anything processing our request.   The end user hammering the keyboard (out of frustration I guess) was showing us a big whole in our logic.

This all now seems a bit obvious, but it really has been stumping us for a while now.      The solution was to put in place is a software latch,  so that once the processing event had been fired it couldn’t be fired again.

This was achieved very simply by adding the following to our  code -

private bool btpostlatch = false;

private void mnuok_Click(object sender, EventArgs e)
            if (btpostlatch) return; // test our latch
            btpostlatch = true;

            this.mnuok.Enabled = false;

// etc.   please remember that if there is a problem to set latch back to false

Now I’m sure this can be achieved a number of different ways like disabling the KeyDown handler when actions run etc.   but the latch mechanism provided a good solution for us.

I hope this may save you some time.


Technorati Tags:
posted on Wednesday, April 29, 2009 3:50 PM