在.NET Core/标准类库中显示消息框 [英] Show a Message box in a .NET Core/Standard Class Library

查看:60
本文介绍了在.NET Core/标准类库中显示消息框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好.标题怎么说,如何显示.NET Core或Standard Class Library方法中的消息框?我需要执行此操作,因为如果必须使用try/catch语句,我想显示一个带有异常消息错误的消息框.我尝试添加Winforms 引用类库,但找不到System.Windows.Forms.dll.

Hello. How the title says, how I can show a message box in a method of a .NET Core or Standard Class Library? I need to do this because If I have to use try/catch statment, I want to show a message box with the exception message error. I tried adding winforms reference to class library but I cannot found System.Windows.Forms.dll. Any suggestion?

推荐答案

您正在开发哪种.NET Core应用程序?是Web应用程序还是控制台应用程序?

What kind of .NET Core application are you developing? Is it a Web Application or a Console Application?

无论哪种情况,您都可以在catch块中设置如下所示的断点:

Either case you can set a breakpoint in the catch block written like this:

try
{
//Your code
}
catch(Exception e)
{
//You can put a breakpoint on the line above
}

当断点停止运行代码时,您可以检查e中的异常消息.

and when the breakpoint stops the code from running you can inspect the exception message from e.

您还可以在catch块中添加 Console.WriteLine(e.Message)并在控制台中查看错误.

You can also add Console.WriteLine(e.Message) in the catch block and see the error in the Console.

如果您正在开发Web应用程序,并且想稍后再回来查看错误,那么最好在项目中使用记录器.有关记录器的更多信息,请访问https://docs.microsoft.com/zh-cn/aspnet/core/fundamentals/logging

If you are developing a web application and you want to come back and see the error later, then it's better to use a logger with your project. For more information on loggers look at https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging

希望有帮助.


这篇关于在.NET Core/标准类库中显示消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆