0

I realize this sort of question has been asked before, but I have a very specific (and a rather complicated) case that is subtly different, so the usual solutions either do not work or do not apply.

Basically, I have a console app which is launched by a VSIX debugger launcher. The purpose of this app is to load a hosted DLL, establish the appropriate environment, and allow debugging of the DLL's source code from Visual Studio the same way a normal C# project would be debugged. The difference is that this project is not an executable, but a library, and so it needs a host (i.e. the console app in question). It's all very similar to how ASP.NET projects work with IIS/IIS Express - it's just that I wrote a custom host and I manage its launching from my custom VSIX.

The custom host app is a .NET Core Console app and the debugger launches it without any windows. This is deliberate, since it needs no interactive input and all output is redirected to the Visual Studio's debugger session (i.e. the Events tab).

The app is also generic, so it can't know the name of the debugged project until it's actually started. On top of that, I can have multiple instances of Visual Studio debugging multiple different projects at the same time!

I would really like to ease differentiation of these processes in Task Manager, so that they each showed as the name of the specific DLL project that is being hosted in each respective instance. My attempts so far have been:

// 1. This crashes with InvalidOperationException because there is no window.
Console.Title = loadedDllProjectName;

// 2. This doesn't crash, but has no effect, either.
[DllImport("user32.dll")]
static extern int SetWindowText(IntPtr hWnd, string text);
...
SetWindowText(Process.GetCurrentProcess().MainWindowHandle, loadedDllProjectName);

FWIW, the Task Manager shows the process under its default image name and lists it among background processes. The latter is fine and expected. But I would like to change the former. How?

UPDATE According to this, my pursuit might sadly be hollow. Still hoping for an encouraging hint, though!

aoven
  • 2,248
  • 2
  • 25
  • 36
  • FYI: For now, I'm going with a slightly cumbersome solution that involves copying the host app executable under the same name as the hosted DLL (sans file extension). This solves a part of the immediate problem, but it's not ideal. I'm leaving the question open until a better solution is found. – aoven Sep 15 '20 at 11:51
  • I think [this](https://stackoverflow.com/a/18791953/3276027) old answer still apply today for win10 and other windows versions: you cannot set the name of a process, you will find the name of executable file running in task manager And as you have experienced, if your process has no window you cannot set any window text. As far as I know, what you are trying to get is not possible. I'd be glad to be wrong and learn something new – Gian Paolo Sep 15 '20 at 12:38

0 Answers0