I was glad to integrate your code into my C# application.
Actually, within the debugger windows, I can't recognize any human-readable reference to the calling process, but the function is working. :)
So, for whoever may be interested, the following code is my C# 4 equivalent:
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
namespace MyApp.Diagnostics
{
public static class DebugHelper
{
[DllImport("kernel32.dll")]
static extern bool IsDebuggerPresent();
[DllImport("kernel32.dll")]
static extern void DebugBreak();
public static bool AttachCurrentProcessToDebugger()
{
try
{
if (!IsDebuggerPresent())
{
var sExePath = Path.Combine(Environment.SystemDirectory,
"VSJitDebugger.exe");
var process = Process.Start(sExePath, " -p " +
Process.GetCurrentProcess().Id);
process.WaitForExit();
if (process.ExitCode != 0)
return false;
for (int i = 0; i < 5 * 60; i++)
{
if (IsDebuggerPresent())
break;
Thread.Sleep(200);
}
}
DebugBreak();
return true;
}
catch (Exception ex)
{
var sExMessage = (ex.InnerException != null ?
ex.InnerException.Message + "; " : string.Empty)
+ ex.Message
+ ((ex.TargetSite != null) ? ex.TargetSite.ToString() : string.Empty);
Debug.Print(ex.GetType().Name + ": " + sExMessage + ex.StackTrace);
return false;
}
}
}
}
I am currently busy in the apparel industry developing software for cutting machines.
Over the past 15 or more years I did work in this field, initially as a technician.
After a ZX Spectrum lit my path in the 80s, I played with many technologies, ranging from DOS to Windows, evolving my interests from a school matter into an hobby, then a passion and finally into a full-time job.
Since the 90s I engaged with Basic, Pascal, Assembly, Batch files, C, C++, Visual-Basic, Java(script), VBScript, T-SQL, HTML, ASP, FoxPro, C#, always trying to grasp any available language tool (the last being Generics, Linq, IL, Expression trees).
I can claim experience for many kind of contexts, mainly DB, PM and CAD/CAM.
I'm information hungry and always try to improve my skills.
Apart from High school graduation, I have no specific certificate or title, but I can count on an enough sharp know-how (at least within the fields I'm not worry to step into).