Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CLR20R3错误-文本到图像到图标呈现问题(包括线程)-VB.net_Vb.net_Multithreading_Background Process - Fatal编程技术网

CLR20R3错误-文本到图像到图标呈现问题(包括线程)-VB.net

CLR20R3错误-文本到图像到图标呈现问题(包括线程)-VB.net,vb.net,multithreading,background-process,Vb.net,Multithreading,Background Process,我有一个计时器,每半秒钟就响一次。它调用一个后台进程,将文本呈现为图标,并将其用于通知图标 Public Shared DISCUS(9) As NotifyIcon Private Sub BackgroundProcess2_DoWork() Handles BackgroundProcess2.DoWork Try For counter As Integer = 0 To My.Computer.FileSystem.Dr

我有一个计时器,每半秒钟就响一次。它调用一个后台进程,将文本呈现为图标,并将其用于通知图标

Public Shared DISCUS(9) As NotifyIcon
        Private Sub BackgroundProcess2_DoWork() Handles BackgroundProcess2.DoWork
           Try
              For counter As Integer = 0 To My.Computer.FileSystem.Drives.Count - 1
                    Dim FontColor As Color
                    If Math.Round((this / that) * 100, decimals:=0) < 25 Then
                        FontColor = Settings1.Default.CriticalColor
                    ElseIf Math.Round((this / that) * 100, decimals:=0) >= 25 And Math.Round((actualsize / ofsize) * 100, decimals:=0) < 50 Then
                        FontColor = Settings1.Default.WarningColor
                    Else
                        FontColor = Settings1.Default.NominalColor
                    End If
                    Dim BackColor As Color = Color.Transparent
                    Dim FontName As String = Settings1.Default.InterfaceFont.Name
                    Dim FontSize As Integer = 9
                    Dim iHeight As Integer = 16
                    Dim iWidth As Integer = 16
                    Dim objBitmap As New Bitmap(iWidth, iHeight)
                    Dim objGraphics As Graphics = Graphics.FromImage(objBitmap)
                    Dim objFont As New Font(FontName, FontSize)
                    Dim objPoint As New PointF(1, 0)
                    Dim objBrushForeColor As New SolidBrush(FontColor)
                    Dim objBrushBackColor As New SolidBrush(BackColor)
                    objGraphics.FillRectangle(objBrushBackColor, 0, 0, Width, Height)
                    objGraphics.DrawString(Text, objFont, objBrushForeColor, objPoint)
                    Dim img As Bitmap = objBitmap
                    Dim hIcon As IntPtr = img.GetHicon()
                    Dim icn As Icon = Icon.FromHandle(hIcon)
                    DISCUS(counter).Text = My.Computer.FileSystem.GetDriveInfo(My.Computer.FileSystem.Drives.Item(counter).ToString).VolumeLabel & vbCrLf & "Free space:" & vbCrLf & actualsize & stringvalue1 & " of " & ofsize & stringvalue2 & " (" & (Math.Round((this / that), decimals:=2) * 100) & "%)"
                    DISCUS(counter).BalloonTipText = Text
                    DISCUS(counter).Icon = icn
                    icn.Dispose()
                    DISCUS(counter).ContextMenuStrip = ContextMenuStrip1
                Next
            Catch ex as exception
                    My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.Desktop & "\DT crash log.txt", "Log: " & My.Computer.Clock.LocalTime.Date.ToString & vbCrLf & o.ToString & vbCrLf & vbCrLf, True)
            End Try
        End Sub
作为NotifyIcon的公共共享铁饼(9)
私有子BackgroundProcess2_DoWork()处理BackgroundProcess2.DoWork
尝试
对于My.Computer.FileSystem.Drives.Count-1,计数器为整数=0
颜色
如果数学四舍五入((这个/那个)*100,小数:=0)<25,那么
FontColor=设置1.Default.CriticalColor
如果数学四舍五入((这个/那个)*100,小数:=0)>=25,数学四舍五入((实际大小)*100,小数:=0)<50,则
FontColor=设置1.Default.WarningColor
其他的
FontColor=设置1.Default.NominalColor
如果结束
暗背景色为Color=Color.Transparent
Dim FontName As String=Settings1.Default.InterfaceFont.Name
Dim FontSize为整数=9
将iHeight设置为整数=16
Dim I宽度为整数=16
将objBitmap变暗为新位图(iWidth、iHeight)
Dim objGraphics As Graphics=Graphics.FromImage(objBitmap)
Dim objFont作为新字体(FontName、FontSize)
将对象点变暗为新点F(1,0)
作为新SolidBrush(FontColor)的暗淡objBrushForeColor
作为新的SolidBrush的暗淡背景色(背景色)
objGraphics.FillRectangle(objBrushBackColor,0,0,宽度,高度)
objGraphics.DrawString(文本、objFont、objBrushForeColor、objPoint)
将img调为位图=objBitmap
作为IntPtr=img.GetHicon()的尺寸hIcon
尺寸icn作为图标=图标。从手柄(hIcon)
DISCUS(计数器).Text=My.Computer.FileSystem.GetDriveInfo(My.Computer.FileSystem.Drives.Item(计数器).ToString.VolumeLabel&vbCrLf&“可用空间:&vbCrLf&actualsize&stringvalue1&”of“&ofsize&stringvalue2&”(“&(Math.Round((这个/那个),小数:=2)*100)&”)
铁饼(计数器)。BalloodTiptExt=文本
铁饼(计数器)。图标=icn
icn.Dispose()
DISCUS(计数器).ContextMenuStrip=ContextMenuStrip1
下一个
特例
My.Computer.FileSystem.WriteAllText(My.Computer.FileSystem.SpecialDirectories.Desktop&“\DT crash log.txt”,“log:”&My.Computer.Clock.LocalTime.Date.ToString&vbCrLf&o.ToString&vbCrLf&vbCrLf,True)
结束尝试
端接头
现在由于某种原因,在应用程序激活几分钟后,我得到一个JIT弹出窗口,它不会呈现任何文本或按钮。单击它会导致JIT调试器崩溃,我得到的窗口“{App}已停止响应。”错误代码为CLR20R3。我不确定这是怎么回事,但如果需要,我可以提供任何其他细节。 我把所有东西都嵌套在Try/Catch语句中,所有代码都要写入崩溃日志,但没有写入任何内容,我仍然会收到错误消息


有人能给我一些建议吗?

我无法从您的代码片段中确定,但我怀疑问题在于您试图从后台线程更新用户界面线程上的某些内容。这将不可避免地导致像您所经历的那样的崩溃

如果更新用户界面,则必须对UI线程上运行的对象使用Invoke。这里有几个链接可以让您开始了解这一点:


第二个线程看起来非常有用,我现在正试图实现调用……第二个线程让我找到了答案。我正在运行我的应用程序,查看它是否崩溃。如果没有,我会开始设计图标,我会为这个相当漂亮的实用程序提供一个下载链接!遇到GDI+问题。。。它不会立即发生,但当它发生时,即使我单击“继续”,它也会持续发生……这可能是您在使用GDI+时遇到的问题吗:不,一定是其他问题。我是以编程方式创建图像的,我是否应该将其渲染到一个文件中,然后加载它?