Application hang on hitting iTask button

A

ataha

Ive got a medical application running on an iPAQ h4150. In the
application, I receive data packets via bluetooth from a data
acquisition device. Because the application can be connected to many
devices at the same time, once I get to the last data packet on a
particular device, I start a thread for the results calculation and
writing of results into the data file (xml). The reason for this is
that it takes several seconds to calculate and display the results, and
I dont want the GUI to be unresponsive during this time since if youve
got 7 devices running at the same time this will block the gui for
about 30 seconds. The thread code look slike this

calculationThread = new System.Threading.Thread(new
System.Threading.ThreadStart(CalculateResults));
calculationThread.Start();

where CalcualteResults is something like this

public void CalculateResults()
{
CalculateReadings
WriteResultsToXml
DisplayResultsInADataGrid

this.Invoke(new EventHandler(FinishedCalculating));
}

FinishedCalculating just displays a message to the user and sets some
local variables

I use a mutex to make sure that only one thread is writing to the data
file at the same time. If I run the application without interference
from the user there is no problem. However, if, right at the end of
data sampling just where the thread is created, i hit the iTASK button
(the one that displays running applications to the user), the
application hangs. Even if i run the application in debug mode it
hangs. If I then press "pause", the executing instruction could be
anywhere, and if press continue, and then press pause again, it shows
that the executing instruction has not moved at all.

Is anyone aware of whats going on here ?
Any help is appreciated
Taha
 
D

Daniel Moth

What happens if you move DisplayResultsInADataGrid to FinishedCalculating as
well? If it touches UI elements it should not be performed by the worker
thread.

Cheers
Daniel
 
A

ataha

Daniel said:
What happens if you move DisplayResultsInADataGrid to FinishedCalculating as
well? If it touches UI elements it should not be performed by the worker
thread.

Cheers
Daniel

Well since I posted I attempted to invoke DisplayResultsInADataGrid
too, and that did nothing. What I should have mentioned also is that
ive got breakpoints in the WriteToXml part of the code, and when I
click the iTask button (I think all this does is forces the form to
repaint), the application hangs without hitting the breakpoints. So its
not even getting past the WriteToXml part. I can click the iTask button
as many times as I want before the thread is up and everything is fine,
but it seems that as soon as this "CalculateAndDisplay" thread is up,
forcing the form/tabpage/controls/tabcontrol to repaint is freezing the
application.

Taha
 

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