每个人。我希望在这场大流行中一切都好。
我有一个维护程序,多年来我一直在成功使用以下功能,直到我们最近从Windows 7更改为Windows 10。
除其他外,我的程序还显示了扫描到Xerox Docushare中的PDF文档。这些文档与条形码中的参考ID相关联。一张封面(条形码)可能有一个或几十个扫描实例。
我有一个用户定义的控件(ucDocushare_DocumentSetByRefID.vb),该控件具有ListView(lvwDocuments)和TabControl(tcDocumentScanInstances)。功能是ListView显示代表扫描集的封面。当用户单击ListView中的项目时,将显示TabControl,其中包含与所选封面相关的每个单独扫描实例的选项卡。
每时每刻,没有明显的原因,当我单击ListView中的封面项目时,程序将直接终止。在Visual Studio 2015中进行调试时,显示以下消息。它与文档的大小或扫描实例的数量无关。我成功地打开了很多页面的大型文档。我也有许多成功扫描实例出现。
System.accessViolationException未处理 消息:System.Windows.Forms.dll中出现了“ System.accessViolationException”类型的未处理异常
其他信息:尝试读取或写入受保护的内存。这通常表明其他内存已损坏。
此外,“中断模式”选项卡将显示以下内容:
应用程序处于中断模式
您的应用已进入中断状态,但由于所有线程都在执行外部代码(通常是系统代码或框架代码),因此没有可显示的代码。
从此的“结束子行”开始时,立即发生错误:
Private Sub tcDocumentScanInstances_DrawItem(sender As Object,e As DrawItemEventArgs) _
Handles tcDocumentScanInstances.DrawItem
此DrawItem子标签为标签标签做了一些字体管理,但主要决定了在这些标签上显示哪个图标。
这是该子代码的完整代码:
'Color code document tab labels and display appropriate icons.
Private Sub tcDocumentScanInstances_DrawItem(sender As Object,e As DrawItemEventArgs) _
Handles tcDocumentScanInstances.DrawItem
Try
Dim intTabIndex As Integer = 0
' Identify which TabPage is currently selected
Dim SelectedTab As TabPage = tcDocumentScanInstances.TabPages(e.Index)
' Get the area of the header of this TabPage. This is the actual label for the tab page.
Dim HeaderRect As Rectangle = tcDocumentScanInstances.GetTabRect(e.Index)
' Create a Brush to paint the Text
Dim sbBlackBrush As New SolidBrush(Color.Black)
Dim sbRedBrush As New SolidBrush(Color.Red)
' Set the Alignment of the Text
Dim sf As New StringFormat()
sf.Alignment = StringAlignment.Center
sf.LineAlignment = StringAlignment.Center
' Paint the Text using the appropriate Bold setting
Dim intIconPositionX As Integer = HeaderRect.Left + 4
Dim intIconPositionY As Integer = HeaderRect.Top + 7
Dim dicImages As New Dictionary(Of String,Image)()
dicImages("Tab" & e.Index) = Nothing ' Set the value of the "variable"
tcDocumentScanInstances.Padding = New System.Drawing.Point(15,15)
'tcDocumentScanInstances.TabPages(0).Width = 500
If Convert.ToBoolean(e.State And DrawItemState.Selected) Then
Dim BoldFont As New Font(tcDocumentScanInstances.Font.Name,tcDocumentScanInstances.Font.Size,FontStyle.Bold)
e.Graphics.FillRectangle(New SolidBrush(systemcolors.ButtonFace),e.Bounds)
If tcDocumentScanInstances.TabPages(e.Index).Tag Is Nothing Then
tcDocumentScanInstances.TabPages(e.Index).Tag = ""
End If
Select Case tcDocumentScanInstances.TabPages(e.Index).Tag.ToString
Case "Delete","Delete Client Letter","Excessive Documentation"
dicImages("Tab" & e.Index) = ilTabIconsForDocumentScanInstances.Images(IconsForDocumentScanInstances.DeleteDocument)
e.Graphics.DrawString(SelectedTab.Text,BoldFont,sbRedBrush,HeaderRect,sf)
sbRedBrush.Dispose()
Case "No Documentation"
dicImages("Tab" & e.Index) = ilTabIconsForDocumentScanInstances.Images(IconsForDocumentScanInstances.NoDocumentExists)
e.Graphics.DrawString(SelectedTab.Text,sbBlackBrush,sf)
sbBlackBrush.Dispose()
Case Else
dicImages("Tab" & e.Index) = ilTabIconsForDocumentScanInstances.Images(IconsForDocumentScanInstances.DocumentExists)
e.Graphics.DrawString(SelectedTab.Text,sf)
sbBlackBrush.Dispose()
End Select
e.Graphics.DrawImage(dicImages("Tab" & e.Index),intIconPositionX,intIconPositionY)
Else
e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(128,167,240)),e.Bounds)
If tcDocumentScanInstances.TabPages(e.Index).Tag Is Nothing Then
tcDocumentScanInstances.TabPages(e.Index).Tag = ""
End If
Select Case tcDocumentScanInstances.TabPages(e.Index).Tag.ToString
Case "Delete",e.Font,sf)
sbRedBrush.Dispose()
Case "No Documentation","Missing Documentation"
dicImages("Tab" & e.Index) = ilTabIconsForDocumentScanInstances.Images(IconsForDocumentScanInstances.NoDocumentExists)
e.Graphics.DrawString(SelectedTab.Text,intIconPositionY)
End If
If tcDocumentScanInstances.SelectedTab.Tag Is Nothing Then
tcDocumentScanInstances.SelectedTab.Tag = ""
End If
If frmCaseMaintenance.tcDocumentationByRefID.TabPages( _
frmCaseMaintenance.tcDocumentationByRefID.SelectedIndex).Tag.ToString.Length >= "Delete".Length Then
If frmCaseMaintenance.tcDocumentationByRefID.TabPages( _
frmCaseMaintenance.tcDocumentationByRefID.SelectedIndex).Tag.ToString.Substring(0,"Delete".Length) <> "Delete" Then
'The coversheet and all associated documents,together,are not marked for deletion.
Select Case tcDocumentScanInstances.SelectedTab.Tag.ToString.Trim
Case "Delete","Delete Client Letter"
btnmarkCurrentDocumentForDeletion.Enabled = False
btnUnmarkCurrentDocumentForDeletion.Enabled = True
Case "No Documentation","Missing Documentation"
'A tab displaying a message that there is no documentation can not be deleted.
btnmarkCurrentDocumentForDeletion.Enabled = False
btnUnmarkCurrentDocumentForDeletion.Enabled = False
Case Else
btnmarkCurrentDocumentForDeletion.Enabled = True
btnUnmarkCurrentDocumentForDeletion.Enabled = False
End Select
Else 'the coversheet and all associated documents,are marked for deletion.
btnmarkCurrentDocumentForDeletion.Enabled = False
btnUnmarkCurrentDocumentForDeletion.Enabled = False
End If
Else 'the coversheet and all associated documents,are marked for deletion.
Select Case tcDocumentScanInstances.SelectedTab.Tag.ToString.Trim
Case "Delete","Missing Documentation"
'A tab displaying a message that there is no documentation can not be deleted.
btnmarkCurrentDocumentForDeletion.Enabled = False
btnUnmarkCurrentDocumentForDeletion.Enabled = False
Case Else
btnmarkCurrentDocumentForDeletion.Enabled = True
btnUnmarkCurrentDocumentForDeletion.Enabled = False
End Select
End If
Catch ex As Exception
If Err.Description = "A generic error occurred in GDI+." Then
'This error probably was tripped by this line: e.Graphics.FillRectangle(New SolidBrush(systemcolors.ButtonFace),e.Bounds)
'tabDocumentScanInstance_DrawItem() will execute again without that line causing a problem,so we do nothing here.
Else
MessageBox.Show( _
"Class Name: " & Me.Name & vbCrLf & _
"Sub Name: tcDocumentScanInstances_DrawItem()" & vbCrLf & _
"Error Number: " & Err.Number & vbCrLf & _
"Message: " & Err.Description,_
gstrExecutableName & " - Error",_
MessageBoxButtons.OK,MessageBoxIcon.Error)
End If
End Try
End Sub
正在使用的产品
microsoft Visual Studio Professional 2015 版本14.0.25431.01更新3
microsoft .NET Framework 版本4.8.03752
尝试的解决方案
-
重新启动计算机
-
删除了可执行文件并生成了一个新文件
-
在命令提示符中执行“ netsh winsock reset”并重新启动;还在命令提示符下执行了“ netsh winsock reset 目录”并重新启动
-
将“平台目标”从“任何CPU”更改为“ x86”。
- [项目名称]属性->“编译”选项卡->“编译选项”->“目标CPU”
- 重建/构建项目。 (当“ x86”无法解决问题时,我将其更改回“任何CPU”。)
-
建议不要在Visual Studio中选中以下内容。已经是了。
Tools menu ->Options -> Debugging -> General -> Uncheck this option "Suppress JIT optimization on module load"
-
使用其他文件副本(相同的日期/时间和文件大小)替换了位于此处的System.Windows.Forms.dll:C:\ Windows \ microsoft.NET \ Framework \ v2.0.50727
我感谢您的投入。