Solved

Why does my Thread hang?

Posted on 2009-05-08
3
300 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

743 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

11 Experts available now in Live!

Get 1:1 Help Now