my PPC application hangs up!

  • Thread starter Thread starter Hari
  • Start date Start date
H

Hari

Hi,

I'm currently working on an IM client application. My app needs to
communicate with the server which, in turn connects to the main IM
servers and returns the response from them to my client applicatioin.
For this, my app creates few worker threads. One of them, which we call
as cmsThread polls at the socket, for the messages sent by the server
and takes appropriate actions to update the UI. Few days i had a prob.
I was receiving an exception when the cmsThread tries to draw the tree
of contactsList. So i modified this to call invoke(). That was solved.
But from then, i have the same prob repeating again and again. That is,
the app is hanging up whenever a nonUI thread is trying to access the
UI elements. And the problem with the CompactFramework is
1) It does not have the isInvokeRequired() function which automatically
detects if the current thread is the UIThread or not
2) The argument to the invoke() should be an event handler.

As isInvokeRequired() is not supported, i'm creating a thread object in
each and every form of the application and assigning the instance of
the currentThread to it in the form_load(). But as my application is
becoming bigger, the problem of hangup is getting intense.

Right now my app hangs once in a while. And this happens after the
contactsList tree is drawn. Even by debugging, i'm unable to identify
the cause. I also suspect if this is because of the many events that
are raised because of the invoke() calls.

Is there any other way to make sure that the UI modification is done
only by the UI thread, instead of doing manually?

Any idea why my app hangs? Please suggest


Thanks,

Hari.
 
Hari,

You should update your CF to CF2.0 SP1. This is the most recent
version of the CF which now implements the Control.InvokeRequired
property to enable you to programatically determine if code is
executing on the UI thread.

Most importantly, I believe you should look at the structure of you
application to avoid these hanging issues that, more than likely, can
be attributed to how you are using the cmsThread.

The class that creates the cmsThread should provide an event e.g.
DataReceivedEvent. From there your UI form(s) should attach event
handlers eg.OnDataReceived. Within the event handler of the form you
can use the InvokeRequired property to determine if the delegate has
been called from the UI thread or from a different thread. If an
Invoke is required, then Invoke().
 
Back
Top