473,503 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multi-threading and code execution problems

Hi,
I have an app that runs many simultaneous threads. I have noticed (took me
a while to figure out what it was doing though) that sometimes if there is a
problem, the thread will simply terminate on the line that caused a simple
exception, but does not throw any error or inform me in any way. I recently
found one of these problems in a function that does an int.Parse(string),
however, there are many more. I was apparently wrong in assuming that
int.Parse would throw an exception if an invalid character was in the string
to be parsed. Instead it simply terminates the thread. I am very careful
with my error handling, and put it everywhere it is required, so that is not
the problem.

Another thread which is running simultaneously MUST wait for a signal from
the thread with the problem in order for it to continue. When it does not
recieve the signal, it continues in an infinite loop until I shut the
program down. This is a huge problem, because the application we are
developing is one that is required to continue operating even if there is a
problem such as this, as it will be running constantly on our server for
2000+ customers.

To clear up any confusion, I'm having a problem with a thread that is
terminating while in the middle of execution. I doubt there is a solution,
but does anyone know of a workaround? Thanks,

Chris LaJoie
Nov 15 '05 #1
1 3403
"Val Savvateev" <1@2.com> wrote in message
news:OW**************@TK2MSFTNGP11.phx.gbl...
I would definetely double-check (or even tripple-check if needed :)) the logic in the thread that's failing. Something causes that thread to return from its main procedure. Is that an unhandled exception or just a forgotten dusty return statement? - to be found out....

(I also don't believe in misteries, and threads terminating with no reason :))

Val.


I agree with Val. Where is your exception handling? I've created a
very simple multi-threaded example attached below:

There are three different methods that can be called in a separate
thread. Method1 has no exception handling and it causes the program
to "bomb" with the following message:

Unhandled Exception: System.FormatException: Input string was not in a
correct format.
at System.Number.ParseInt32(String s, NumberStyles style,
NumberFormatInfo info)
at System.Int32.Parse(String s, NumberStyles style, IFormatProvider
provider)
at System.Int32.Parse(String s)
at Test.Class1.Method1() in c:\documents and settings\mmayer1\my
documents\visual studio
projects\gradebook\testtwobuttons\class2.cs:line 12

Note that the exception is not swallowed by the try...catch... block
in Main(). Method2 and Method3 each swallow exceptions for code
running on the thread, and the application runs.

HTH,
-mike

using System;
using System.Threading;

namespace Test
{
public class Class1
{

public static void Method1()
{
Console.WriteLine("About to parse");
int x = int.Parse("abcdefg");
Console.WriteLine("Finished parsing");
}
public static void Method2()
{
Console.WriteLine("About to parse");
try
{
int x = int.Parse("abcdefg");
}
catch
{
Console.WriteLine("Swallowed exception in Method2");
}
Console.WriteLine("Finished parsing");
}

public static void Method3()
{
Console.WriteLine("About to parse");
try
{
Method1();
}
catch
{
Console.WriteLine("Swallowed exception in Method3");
}
Console.WriteLine("Finished parsing");
}
public static void Main ()
{

try
{
Console.WriteLine("Starting thread");
//Thread thread = new Thread(new
ThreadStart(Method1));
//Thread thread = new Thread(new
ThreadStart(Method2));
Thread thread = new Thread(new ThreadStart(Method3));
thread.Start();
Console.WriteLine("waiting for thread to finish");
while (thread.IsAlive)
{
Thread.Sleep(100);
}
Console.WriteLine("finished waiting for thread to
finish");
}
catch
{
Console.WriteLine("Swallowed error in Main()");
}

Console.ReadLine();
}
}
}

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4630
by: Frank Jona | last post by:
Intellisense with C# and a multi-file assembly is not working. With VB.NET it is working. Is there a fix availible? We're using VisualStudio 2003 Regards Frank
12
3842
by: * ProteanThread * | last post by:
but depends upon the clique: ...
6
4870
by: Joe | last post by:
I have 2 multi-list boxes, 1 displays course categories based on a table called CATEGORIES. This table has 2 fields CATEGORY_ID, CATEGORY_NAME The other multi-list box displays courses based on...
2
3025
by: google | last post by:
Hello everyone, I am having an issue using the "Multi Select" option in a list box in MS Access 2003. I am making a form that users can fill out to add an issue to the database. Each issue can...
5
5703
by: bobwansink | last post by:
Hi, I'm relatively new to programming and I would like to create a C++ multi user program. It's for a project for school. This means I will have to write a paper about the theory too. Does anyone...
2
14695
by: Zlatko Matić | last post by:
Hello. How to reference selected values from a multi-select list box, as a criteria in a query ? Is it possible at all? Regards, Zlatko
5
3236
by: dkelly925 | last post by:
Is there a way to add an If Statement to the following code so if data in a field equals "x" it will launch one report and if it equals "y" it would open another report. Anyone know how to modify...
23
5287
by: Kaz Kylheku | last post by:
I've been reading the recent cross-posted flamewar, and read Guido's article where he posits that embedding multi-line lambdas in expressions is an unsolvable puzzle. So for the last 15 minutes...
3
2079
by: Fred | last post by:
We all agree that multi-core is where the industry is headed. Can the .NET framework take advantage of multi-cores? are the programs written in .NET multi-threaded by default or is additional...
14
3376
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
As far as I know, the C Standard has no mention of multi-threaded programming; it has no mention of how to achieve multi-threaded programming, nor does it mention whether the language or its...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7089
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5581
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5017
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3157
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1515
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.