Solved

Why does my Thread hang?

Posted on 2009-05-08
3
312 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

734 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