Problems with Win Mobile GPS Sample freezing?

It’s been a while since I last used the GPS Sample for managed code provided in the mobile SDK. So I compiled it and added a reference to it in my project confident I’d have GPS data very soon. I added the gps class to a second form, launched the form and yah I had GPS data. However, when I closed the form the application froze/hung. After examing the code I could see where it was going wrong but I wasn’t sure why. Essentially the sample create a basic message loop by taking out a lock on itself and going into a loop where is uses Wait For Multiple Objects to get the notifications from the GPS driver. One of the notifications it waits for includes "close". However, the code that issus the close notification then takes out another lock. This should be a good idea because it waits for the lock the loop has got to be given up before it continue cleaning up the component. The problem is that the loop never seems to get the close notification so the application is now stuck waiting for a lock it will never get. Now I’m not a 100% what the problem is but it would seem that it’s probably something to do with threads. Therefore I moved the GPS class into the main form and exposed the data to the secondary form. This seems to have done the trick. As I say I don’t understand why this is since the loop certainly recieves the notifications about GPS changes so why not the close? Hopefully I’ll realise what the problem is soon, but in the meantime at least I seem to have a workaround.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s