Threading problem - terminating unexpectedly

C

Cyril Madigan

This is a bespoke application that has been developed
using C# (Smart Device Application Template) targetting
Windows CE .NET (4.1), CPU = XScale running on Symbol
handheld scanning devices.

It uses multiple threads to perform background tasks while
the user continues to scan barcodes. The application was
originally developed for a Windows CE 3.0 device but has
recently been deployed onto
Windows .NET 4.1 devices using the Intel XScale PXA250
processor.

Since moving onto the new platform we have started
xperiencing a recurring problem where the application
freezes and the device has to be 'warm' booted for the
user to continue. We have been able to replicate the
problem with our development devices and through debugging
the application we think that the problem ultimatly is
caused by background threads being terminated unexpectedly
without any notification. No errors or exceptions are
being generated when this happens.

The application freezing is a by-product - if a thread
with a lock on the database resource is terminated before
it releases the lock, all future attempts to use the
database resource stall.

Although we are not certain of the cause, we came to this
conclusion by adding logging statements within a
particular method and when the application froze, looking
at the log file to see how far it got. We found that in
one circumstance the thread terminated just before or
while executing a very simple statement as shown below:

while (!endOfWork)
{
// Write message to log (A)
if (index != specialIndex)
{
// Write message to log (B)
// Do some work
// Write message to log (C)
}
// Write message to log (D)
}

The log resulted in a stream of messages such as:
A, B, C, D, A, D, A, D, A, D, A, B, C, D, A

So the thread successfully executed a number of
itterations of the loop but then suddenly stopped just
before or while evaluating the expression inside
the 'if'. A try/catch block around the while loop did not
catch any exceptions.

We had also set the debugger exception options to break
immediately into the debugger whenever any C++ Exceptions,
Common Language Runtime Exceptions, Native Run-Time Checks
or Win32 Exceptions occurred but this never kicked
in.

If we pause the application once we detect a 'freeze', the
thread which should be executing this code is not
displayed in the debuggers list of threads.

However a hashtable which maintains a reference to
all 'managed' threads that have aquired a lock on the
database resource still reports the existance of the
original thread.

Most (if not all) of the background threads are initiated
by a System.Threading.Timer instance.

Any assistance or pointers would be much appreciated.
 
G

Ginny Caughey [MVP]

Cyril,

If the app uses the Symbol SMDK code for barcode scanning, that is
triggering lots of threads. I haven't had any problem using it myself on the
same hardware, but my apps aren't running lots of other threads too, so I
don't know exactly what's going on in your scenario. Do you also have the
problem with the app freezing if you comment out the scanning?

Ginny Caughey
Windows Embedded MVP
 
S

Scott Corbin [MS]

Cyril,

If a thread calls ExitThread in native code then that thread will exit
without any notifications or exceptions being thrown to managed code up the
stack. That's my first guess as to what's happening--a thread is getting
down into native code (I'm assuming that's via your "// Do some work"
block), and for whatever reason/error the native code is calling
ExitThread. Have you tried Ginny's suggestion of commenting out some calls?

Scott Corbin

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "Ginny Caughey [MVP]" <[email protected]>
| References: <[email protected]>
| Subject: Re: Threading problem - terminating unexpectedly
| Date: Tue, 7 Oct 2003 12:13:21 -0400
| Lines: 90
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.framework.compactframework
| NNTP-Posting-Host: rrcs-midsouth-24-199-182-238.biz.rr.com 24.199.182.238
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:35359
| X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework
|
| Cyril,
|
| If the app uses the Symbol SMDK code for barcode scanning, that is
| triggering lots of threads. I haven't had any problem using it myself on
the
| same hardware, but my apps aren't running lots of other threads too, so I
| don't know exactly what's going on in your scenario. Do you also have the
| problem with the app freezing if you comment out the scanning?
|
| Ginny Caughey
| Windows Embedded MVP
|
| | > This is a bespoke application that has been developed
| > using C# (Smart Device Application Template) targetting
| > Windows CE .NET (4.1), CPU = XScale running on Symbol
| > handheld scanning devices.
| >
| > It uses multiple threads to perform background tasks while
| > the user continues to scan barcodes. The application was
| > originally developed for a Windows CE 3.0 device but has
| > recently been deployed onto
| > Windows .NET 4.1 devices using the Intel XScale PXA250
| > processor.
| >
| > Since moving onto the new platform we have started
| > xperiencing a recurring problem where the application
| > freezes and the device has to be 'warm' booted for the
| > user to continue. We have been able to replicate the
| > problem with our development devices and through debugging
| > the application we think that the problem ultimatly is
| > caused by background threads being terminated unexpectedly
| > without any notification. No errors or exceptions are
| > being generated when this happens.
| >
| > The application freezing is a by-product - if a thread
| > with a lock on the database resource is terminated before
| > it releases the lock, all future attempts to use the
| > database resource stall.
| >
| > Although we are not certain of the cause, we came to this
| > conclusion by adding logging statements within a
| > particular method and when the application froze, looking
| > at the log file to see how far it got. We found that in
| > one circumstance the thread terminated just before or
| > while executing a very simple statement as shown below:
| >
| > while (!endOfWork)
| > {
| > // Write message to log (A)
| > if (index != specialIndex)
| > {
| > // Write message to log (B)
| > // Do some work
| > // Write message to log (C)
| > }
| > // Write message to log (D)
| > }
| >
| > The log resulted in a stream of messages such as:
| > A, B, C, D, A, D, A, D, A, D, A, B, C, D, A
| >
| > So the thread successfully executed a number of
| > itterations of the loop but then suddenly stopped just
| > before or while evaluating the expression inside
| > the 'if'. A try/catch block around the while loop did not
| > catch any exceptions.
| >
| > We had also set the debugger exception options to break
| > immediately into the debugger whenever any C++ Exceptions,
| > Common Language Runtime Exceptions, Native Run-Time Checks
| > or Win32 Exceptions occurred but this never kicked
| > in.
| >
| > If we pause the application once we detect a 'freeze', the
| > thread which should be executing this code is not
| > displayed in the debuggers list of threads.
| >
| > However a hashtable which maintains a reference to
| > all 'managed' threads that have aquired a lock on the
| > database resource still reports the existance of the
| > original thread.
| >
| > Most (if not all) of the background threads are initiated
| > by a System.Threading.Timer instance.
| >
| > Any assistance or pointers would be much appreciated.
| >
|
|
|
 

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