VB.net:抑制错误消息问题

发布于 2024-09-12 11:31:14 字数 1515 浏览 3 评论 0原文

我已阅读 MSDN 页面 关于如何抑制消息。我无法抑制 VS2008 的警告。

我已尝试列出以下说明:

  1. 在错误列表中,选择 警告或警告压制。 可以选择多个警告 同时。

  2. 右键单击警告,指向 抑制消息,然后单击 在源代码中或在项目中 抑制文件。

  3. 特定警告已被抑制, 并且警告出现在错误中 带删除线的列表窗口。

但是,当我右键单击“错误列表”时,我只能看到以下选项:

  • 排序依据
  • 显示列
  • 显示错误帮助
  • 复制
  • 上一个错误
  • 下一个错误

为什么 Visual Studios 2008 for VB.net 不显示“禁止消息”

我无法生成以下抑制消息:

<Scope:SuppressMessage("Rule Category", "Rule Id", "Justification", "MessageId", Scope = "Scope", Target = "Target")>

问题是我有一系列依赖于复选框的并行任务。我希望每个任务同时运行然后再加入。我通过使用递减的回调方法克服了警告,直到所有回调完成。

即(根据记忆):

chkbox1.enable = false
chkbox2.enable = false
dim dlgChkbox1 as Action = addressof Task1
dim dlgChkbox2 as Action = addressof Task2
...
if chkbox1.checked = true then
   result = dlgChkbox1.BeginInvoke(nothing,nothing)
end if
if chkbox2.checked = true then
   result = dlgChkbox2.BeginInvoke(nothing,nothing)
end if
...
if chkbox1.checked = true then
    dlgChkbox1.EndInvoke()
end if
if chkbox1.checked = true then
    dlgChkbox2.EndInvoke()
end if
...
chkBox1.enable = true
chkBox2.enable = true

警告是未初始化的变量。事实并非如此,因为它依赖于相同的 if 语句。我选择使用回调方法,事实证明这是一个更好的选择,并且不会锁定 GUI。

I have read the MSDN Page on how to suppress messages. I am unable to supress
warnings for VS2008.

I have tried the following instructions listed:

  1. In the Error List, select the
    warning or warnings to suppress.
    Multiple warnings can be selected at
    the same time.

  2. Right-click the warning, point to
    Suppress Message(s), and click
    either In Source or In Project
    Suppression File.

  3. The specific warning is suppressed,
    and the warning appears in the Error
    List window with a strikethrough.

However, when I right click in the 'Error List' I only get the following options:

  • Sort By
  • Show Columns
  • Show Error Help
  • Copy
  • Previous Error
  • Next Error

Why does Visual Studios 2008 for VB.net not display 'Suppress Messages'?

I cannot generate the following suppressing messages:

<Scope:SuppressMessage("Rule Category", "Rule Id", "Justification", "MessageId", Scope = "Scope", Target = "Target")>

The problem was I had a series of parallel tasks that were dependent on check boxes. I wanted each task to to run simultaneously and then join back. I overcame the warning by using a callback method that decremented until all the call backs completed.

ie (from memory):

chkbox1.enable = false
chkbox2.enable = false
dim dlgChkbox1 as Action = addressof Task1
dim dlgChkbox2 as Action = addressof Task2
...
if chkbox1.checked = true then
   result = dlgChkbox1.BeginInvoke(nothing,nothing)
end if
if chkbox2.checked = true then
   result = dlgChkbox2.BeginInvoke(nothing,nothing)
end if
...
if chkbox1.checked = true then
    dlgChkbox1.EndInvoke()
end if
if chkbox1.checked = true then
    dlgChkbox2.EndInvoke()
end if
...
chkBox1.enable = true
chkBox2.enable = true

The warning was an Uninitialized Variable. Which was not the case as it was dependent on identical if-statements. I opted to use a callback method instead, which turned out to be a better alternative and did not lock up the GUI.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七秒鱼° 2024-09-19 11:31:14

错误的 MSDN 页面。那篇文章讨论了抑制代码分析工具产生的警告。与 VB.NET 编译器截然不同。

要抑制编译器警告,请使用“项目 + 属性”、“编译”选项卡、“警告配置”部分。找到您要禁用的特定警告消息,将通知设置从“警告”更改为“无”。 “禁用所有警告”复选框是最重要的解决方案。

Wrong MSDN page. That one talks about suppressing warnings produced by the Code Analysis tool. Very different animal from the VB.NET compiler.

To suppress compiler warnings, use Project + Properties, Compile tab, Warning configurations section. Locate the specific warning message you want to disable, change the notification setting from "Warning" to "None". The "Disable all warnings" checkbox is the big hammer solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文