Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
public partial class Form1 : Form
   {
       public Form1()
       {
           InitializeComponent();
       }

       private void Form1_Load(object sender, EventArgs e)
       {
           try
           {
              Parallel.Invoke(
                  () => this.BeginInvoke((Action)delegate
                  {
                      FirstLevel();
                  })
                  );
           }
           catch (Exception ex)
           {
               throw;
           }
       }

       private void FirstLevel()
       {
           try
           {
                   SecondLevel();

           }
           catch (Exception ex)
           {
               throw;
           }
       }

       private void SecondLevel()
       {
           try
           {
               ThirdLevel();
           }
           catch (Exception ex)
           {
               throw;
           }
       }

       private void ThirdLevel()
       {
           try
           {
               throw new DivideByZeroException();
           }
           catch (Exception ex)
           {
               throw;
           }
       }

       private void button1_Click(object sender, EventArgs e)
       {
           try
           {
               FirstLevel();
           }
           catch (Exception ex)
           {
               throw;
           }
       }
   }


What I have tried:

I have desktop application in which i have created the one form into which i have called FirstLevel method into parallel threading then firstlevel() method call secondlevel method,secontlevel method call thridlevel method and third level method have exception all method have try catch with throw but whenever exception occured the stack trace got the exception upto Firstlevel method it does not capture the Form1_Load method. ineed the all hierarchy of method into exception.

If i remove the threading FROM Form1_load method then it got the hierarchy exception of method but if i use the threading the it doesn't occurred the form1_Load method
Posted
Updated 19-Sep-18 20:41pm

1 solution

That's because it doesn't exist: each thread gets its own, separate stack (or they would interfere with each other) and the stack trace is - rightly - only able to return information for the stack for the specific thread that threw the exception.

In fact as long as you have enough cores the Form1_Load method is probably going to have been finished and the original thread (the UI thread) stack cleared before the exception is thrown!
 
Share this answer
 
Comments
Member 12893295 20-Sep-18 2:48am    
is any alternative for it
OriginalGriff 20-Sep-18 3:23am    
What part of "it doesn't exist" are you having trouble understanding?
There is no such stack trace, because they are on separate stacks. You need to brush up on what threading is.
Member 12893295 20-Sep-18 3:32am    
I got whatever you told but im just asking to workaround..
OriginalGriff 20-Sep-18 3:58am    
"It doesn't exist".
There is no workaround.

Think about it this way: you order a take away pizza for you and your mates. It arrives, you pay for it. While you are paying for it, your mates tuck in. When you are finished paying - it took a minute to get the right change - you reach for a slice but the box is empty. Your mates have eaten it all. What work around can you do to get a slice of pizza?

Same thing here. It doesn't exist.
Member 12893295 20-Sep-18 6:12am    
Thanks a lot...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900