Solved

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

Posted on 2009-06-29
5
634 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
[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
  • 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

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

749 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