【发布时间】:2023-03-29 15:48:01
【问题描述】:
警告:我在 1 个月前开始使用 c# 编码,之前没有任何编程知识。
我正在使用以下方法在父窗口中将 MessageBox 居中: How to get MessageBox.Show() to pop up in the middle of my WPF application?
我收到警告称 AppDomain.GetCurrentThreadId();方法已经过时,所以我在这里找到了一个“解决方案”:http://www.pinvoke.net/default.aspx/kernel32/GetCurrentThreadId.html
由于代码不适用于 uint,我将其更改为 int,然后更改了 AppDomain.GetCurrentThreadId();进入 GetCurrentThreadId();
[DllImport("kernel32.dll")]
static extern int GetCurrentThreadId();
我编写了一个相当复杂的数据库程序,到目前为止它似乎可以完美运行,并且我理解它背后的大部分代码,所以如果有人能向我解释我对上述“解决方案”的确切做法,我将不胜感激.
【问题讨论】:
-
您正在使用 Platform Invocation 来调用存在于 .Net 框架环境之外的代码 - 在本例中是位于操作系统库 kernel32.dll 中的函数,请参阅docs.microsoft.com/en-gb/dotnet/framework/interop/…你调用的函数是Windows API的一部分