I would like to decide whether it is WPF or form from the DLL side at the time of execution.

Asked 2 years ago, Updated 2 years ago, 39 views

If you have a library (dll) that is shared between WPF and Windows Forms, you can use the Is there any way to determine if the EXE that called the library is WPF, form, or console?

  • You can also use reflection.

[Development Environment]
C#6.0
.NET 4.5.1
VS2015 Preview

windows c# .net

2022-09-29 21:52

2 Answers

If AppDomain has PresentationFramework.dll loaded and System.Windows.Application.Current is not null, you can consider it a WPF app. This is valid if you are using ElementHost on the form but you do not explicitly create Application.


2022-09-29 21:52

I think it is necessary to clarify the purpose a little more.You may just be loading the assembly *, or if you are called from a thread pool, there may be no trace of the stack frame.WPF can host WinForms and vice versa.Also, there are some like ILDASM.EXE that dare launch as a console application before opening the form.

Application.StartupPath…


2022-09-29 21:52

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.