Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.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
.net 执行更新GUI的代码,但GUI从不更新_.net_Vb.net_Winforms_User Interface - Fatal编程技术网

.net 执行更新GUI的代码,但GUI从不更新

.net 执行更新GUI的代码,但GUI从不更新,.net,vb.net,winforms,user-interface,.net,Vb.net,Winforms,User Interface,我有在智能设备(WindowsCE)上运行的现有VB代码。我对代码进行了编辑,使其具有一种“模拟模式”,在这种模式下,它为windows而不是基于预处理器指令的CE进行编译。为了让运行模拟设备的用户在不读取日志文件的情况下理解正在发生的事情,我尝试添加一个UI。当前,任何用于更新UI的代码都在执行,但更改从未出现 以下是我迄今为止所做的尝试: Public Module SomeDevice #If __SIMULATE__ Then Private WithEvents _derp

我有在智能设备(WindowsCE)上运行的现有VB代码。我对代码进行了编辑,使其具有一种“模拟模式”,在这种模式下,它为windows而不是基于预处理器指令的CE进行编译。为了让运行模拟设备的用户在不读取日志文件的情况下理解正在发生的事情,我尝试添加一个UI。当前,任何用于更新UI的代码都在执行,但更改从未出现

以下是我迄今为止所做的尝试:

Public Module SomeDevice

#If __SIMULATE__ Then
    Private WithEvents _derp As New SimulatorGUI()
    Private _guiShown As Boolean = False
    Private _guiLoading As Boolean = False

    Private Sub handleShown(sender As Object, e As EventArgs) Handles _derp.Shown
        _guiShown = True
    End Sub

    Private Sub handleLoading(sender As Object, e As EventArgs) Handles _derp.Load
        _guiLoading = True
    End Sub

#End If

   Public Sub Main()
   #If __SIMULATE__ Then
        Dim GUIThread As Threading.Thread = New Threading.Thread(Sub() _derp.ShowDialog()) 
        'I have also tried System.Windows.Forms.Application.Run(_derp))

        GUIThread.Name = "Simulator GUI"
        GUIThread.Start()

        While Not _guiLoaded OrElse Not _guiShown
            Thread.Sleep(0)
        End While

        SimulatorGUI.PutOnGUI("Loaded and shown")

 #End If
 'normal device functionality
   End Sub
End Module
在SimulatorGUI类中:

Public Class SimulatorGUI
    Public Sub PutOnGUI(ByVal message As String)
        If Me.InvokeRequired Then
            Me.Invoke(Sub() PutOnGUI(message))
        Else
            ListBox1.Items.Add(message)
            Debug.WriteLine("DOING STUFF: " + message)
            'ListBox1.Invalidate()
            ListBox1.Update()
        End If
    End Sub
End Class

如果我运行这段代码,会显示调试打印,listbox内部集合会显示它包含预期的文本,但该文本永远不会显示在GUI上。此外,“invokererequired”检查不会导致调用Me.Invoke。如果重要的话,其余的设备代码完全按照预期运行。这里出了什么问题?

您没有从创建的实例调用代码

尝试将代码更改为:

'SimulatorGUI.putangui(“加载并显示”)
_derp.普通话(“加载并显示”)

FYI
Application.Run()
是显示第一个表单的正确方式,因为它还创建了UI消息循环。谢谢,这一点现在看起来很明显哈