Solved

Why does my Thread hang?

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to Office 1 44
Adding where clause to entity statement c# 1 48
orderby list (from Json) 1 30
Return array 3 20
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

733 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