OpenNetCF's ConnectionManager.Connect() works only once in a while

C

cyberco

Using: WM5 PPC, .NetCF2.0, OpenNetCF

Somehow I was cheering too early. After a while the snippet below
stopped working and I'm at a loss why. During the first few runs this
snippet nicely connected to the GPRS network: the 'connecting...'
balloon popped up and everything went fine from there. But now the
'connMgr.Status' never becomes 'ConnectionStatus.Connected' and a
timeout occurs. Standby, rebooting, nothing solves this problem.

When connected via ActiveSync the snippet below works fine IF I set the
'exclusive' parameter to 'true'.
I also tried adding a 'Guid' as a parameter,
connMgr.Connect(guid,false, ConnectionMode.Asynchronous), but the
result was that the connection (popping up the balloon) was made only
once. After that the balloon stayed away and the connection was never
made.

Could it be that the connection manager is unable to start a new
connection if it has started one already in the past? In that case I
would say that the a complete reboot of the phone should solve the
problem, but it doesn't.

=============================
bool connected = false;
int timeOut = 20; //seconds
ConnectionManager connMgr = new ConnectionManager();
//connMgr.Connect(true, ConnectionMode.Asynchronous);
connMgr.Connect(false, ConnectionMode.Asynchronous);
while (!connected) {
if (connMgr.Status != ConnectionStatus.Connected) {
Thread.Sleep(1000);
if (timeOut == 0) {
return;
}
timeOut -= 1;
continue;
}
connected = true;
}
=============================
 
C

cyberco

I finally got it working, but boy, what a hack.

First of all it was necessary to get the right GUID. The MapUrl()
function I used with a regular webaddress as parameter wasn't returning
anything useful.

So now I iterate over the DestinationInfo's and search for the one with
the description "The Internet". Beware that the description is a weird
string, since using String.Equals() on it throws an exception, and
anything following this description on, say, a MessageBox won't be
displayed. So the only way to solve this is to use String.StartsWith().

Then it appeared that I HAVE to update the display somehow to make the
'balloon' appear. My application is full screen and I use the 'waiting
cursor', but those are not the problem. When I, just before calling
ConnectionManager.Connect(), show a temporary Form and close it again
immediately the problem disappears (the balloon appears and the
connection is made). Now that's an ugly hack, but it's the only way I
got the ConnectionManager working.

=================================
bool connected = false;
int timeOut = 25; //seconds
ConnectionManager connMgr = new ConnectionManager();
DestinationInfo destInfo = null;
DestinationInfoCollection dic = connMgr.EnumDestinations();
foreach (DestinationInfo di in dic) {
if (di.description.ToLower().StartsWith("The Internet".ToLower()))
{
destInfo = di;
break;
}
}

if (destInfo == null) {
throw new Exception("No destination info");
}

//HACK
Form tmpForm = new Form();
tmpForm.Dispose();

connMgr.Connect(destInfo.guid, true, ConnectionMode.Asynchronous);
while (!connected) {
if (connMgr.Status != ConnectionStatus.Connected) {
Thread.Sleep(1000);
if (timeOut == 0) {
throw new Exception("gprsAttachFailed");
}
timeOut -= 1;
continue;
}
connected = true;
}
=================================
 
C

cyberco

Wow! Impressive research, you're obviously much deeper into .Net than I
am :) Thanks for hunting the problem down.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top