Solved

Breakpoints NOT hit when console application run through System.Diagnostics.Process

Posted on 2009-06-29
5
617 Views
Last Modified: 2012-05-07
Hi there,

I have a simple console application which is running fine (.NET 2.0 and Visual Studio 2005). I have placed some breakpoints within the console application and these breakpoints are hit when I execute the console application through visual studio by marking the console project as startup project.  Till this point everthing is fine.

But when I tried to execute the console project using WindowsForm which is using Process() to execute the console project. The console project is running fine with process.Start(), but the problem is that the breakpoints within the console application are NOT hit when I execute the console application through Process() class. I will be thankful for your help.
0
Comment
Question by:tech1guy
  • 3
  • 2
5 Comments
 
LVL 39

Expert Comment

by:abel
ID: 24739838
Breakpoints are only hit when you attach a debugger to them. To attach a debugger, you will have to go to Visual Studio after you used Process.Start and then you can select Debug > Attach to Process. From then on, when a break point is hit, it will show in the debugger of Visual Studio.

0
 

Author Comment

by:tech1guy
ID: 24739906
which process I need to attach? When I try to attach the TestForm.exe (where I am calling console app through Process), it says that it is already attached. I am executing through F5.
Moreover, is there a way to programaticaaly attach the debugger to Procees?
0
 
LVL 39

Expert Comment

by:abel
ID: 24740433
It is probably possible to programmatically attach the debugger.

It seems to me that we're mixing two things here. You have one process, let's call it procA.exe and you have another process, which you call TestForm.exe. The second process uses a Process.Start(procA.exe) to start the first process. When you debug TestForm.exe, you cannot debug another process with the same debugger. Either run Testform.exe the normal way (from Explorer) or open a new Visual Studio instance and select Attach To Process in that one, in which way you can debug multiple processes at the same time.
0
 
LVL 39

Accepted Solution

by:
abel earned 500 total points
ID: 24740479
As an alternative, you can try to put the following line somewhere in the beginning of your application procA.exe:

System.Diagnostics.Debugger.Launch()

which will popup with a request for debugging, or not if you have already set it to use the default.

ScreenShot413.png
0
 

Author Closing Comment

by:tech1guy
ID: 31598102
Thanks for the help!
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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

919 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

14 Experts available now in Live!

Get 1:1 Help Now