From: Andy Baker on
I have a VB.NET/C# 2005 application that runs on a CE5 device. Currently I
connect to a LAN via a WiFi connection and have been asked to make the
required changes to connect via GPRS instead. This is giving me problems.
The existing working code for the WiFi connection consists of a single call
(Connect) that returns true or false depending on whether it has been
successful or not and I would like to code the same for the GPRS connection.
The problem I have is that the supplied SDK for the device means that in
order to connect to the GPRS network I have to make 2 calls - Initialise and
Connect, and when I call the SDK functions they return to the .NET code
immediately, while the device is still initialising etc. I cannot move on to
the second call until the first call is completed so I need to put in some
sort of delay with a timeout that waits until the call is complete. The sole
method of communicatiing with the SDK function is an event,
OnGPRSResultMsg(strMessage), that fires whenever a message is received at
the GPRS port - e.g. when the initialising is complete I get back the
message WM_GPRS_INIT. I have created a GPRS class and created a string
variable within the class called strGPRSResult that is set to whatever is
received at the GPRS port but am having problems implementing the delay. I
have a test application that consists of a button for each call and displays
the result message that comes back, and this works well so I know that the
individual calls work. However, if I put in a loop after the initialisation
call with a timeout of say 60 seconds, then the OnGPRSResultMsg event
doesn't fire until after the loop is completed - even though it normally
only takes 20-30 seconds to initialise. It seems like the loop is taking
priority and it cannot deal with the event until the loop is completed -
hopefully I have explained that well enough.
I am thinking that what I want to do is create a secondary thread to send
data to and monitor the GPRS port and suspend the main thread until either
the required response has been received or it has timed out. If I was
actually reading the port from my application then that would work as the
secondary thread would just loop round checking the port for data and I
could use Join to suspend the main thread until the secondary thread
completed. However the SDK code reads the port and translates it into an
event and a message string, and I am unsure if I can add an event handler to
the secondary thread. Any suggestions would be appreciated. Thanks in

Andy Baker