Solved

Why does my Thread hang?

Posted on 2009-05-08
3
303 Views
Last Modified: 2013-11-25
Im developing a windows application (not Internet based) using Visual Studio 2008 and Visual C#. Its an MDI application.

The thread enters this "getTriggerWaveform_DLL" function (shown below) but very occasionally never  returns from it. It just vanishes into a black hole. I cant set debugging for this function either. Ive tried and I asked on this forum but the solutions proposed dont work. The function is compiled into a DLL. The thing is Id expect it to at the very least throw an exception back to the calling statement.

Can anyone suggest a modification to this routine such that I should always get an exception thrown back if something goes wrong?

extern "C" __declspec(dllexport) double* getTriggerWaveform_DLL(long channelNo, long noOfPoints, double* timeIncrement, double* startTime) throw(exception) {
      double* results = new double[noOfPoints];

      try{
            theDSO -> getTriggerWaveform(channelNo, noOfPoints, results, timeIncrement, startTime);
      } catch(DSOCPPException e){
            setLastException(e.what());
            throw e;
      }
      return results;
}
0
Comment
Question by:rangers99
  • 2
3 Comments
 
LVL 40

Accepted Solution

by:
evilrix earned 150 total points
ID: 24334432
How do you know that getTriggerWaveform ever returns? How do you know it's a C++ exception being thrown? It might be a structured exception being thrown, not a C++ exception. For this you need to look at Structured Exception Handling (SEH).

http://msdn.microsoft.com/en-us/library/ms680657(VS.85).aspx
http://msdn.microsoft.com/en-us/library/8c522k35.aspx

Also, exceptions should NEVER be allowed to cross an API boundary. The calling langauge may not be the same as the libraries language. So, if getTriggerWaveform was a managed code DLL, for example, and it throws a managed exception across the API boundary you have absolutely no chance of catching it using unmanaged C++.
0
 
LVL 40

Assisted Solution

by:evilrix
evilrix earned 150 total points
ID: 24334452
Additional...

catch(DSOCPPException e)

NEVER catch by value... if it's a polymorphic exception class you'll slice it. Also, you'll copy the exception object (wasteful). Always catch by reference and catch using the highest type int he class hierarchy that you can so as to be able to discern the exception type.

catch(std::runtime_error const & e)
{
}
catch(std::exception const & e)
{
}

Do you expect DSOCPPException from this function?
0
 

Author Comment

by:rangers99
ID: 24336380
evilrx
Thanks for those  answers. Im inexperienced at this but Ill read the those links. cheers.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
detecting  the added row index in a datagridview 3 58
Loop not working 29 47
Sum Column in GridView 3 42
Name space syntax error 12 40
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now