1

私は他の場所で試しましたが、何も起こりませんでした。基本的に、画像をピクチャボックスに表示したい。

私のコード:

Dim ScreenReceiverClient As New TcpClient
Dim ScreenReceiverServer As New TcpListener(ScreenReceiverPort)
Dim ScreenReceiverListening As New Thread(AddressOf ScreenListen)
Dim GetScreen As New Thread(AddressOf ReceiveScreen)
Private Sub ReceiveScreen()
    While ScreenReceiverClient.Connected = True
        Call New Action(AddressOf ChangeImage).BeginInvoke(Nothing, Nothing)
    End While
End Sub
Private Sub ChangeImage()
    Dim bf As New BinaryFormatter
    PictureBox1.Image = bf.Deserialize(ScreenReceiverClient.GetStream)
End Sub
Private Sub ScreenListen()
    While ScreenReceiverClient.Connected = False
        ScreenReceiverServer.Start()
        ScreenReceiverClient = ScreenReceiverServer.AcceptTcpClient
    End While
    GetScreen.Start()
End Sub

ChangeImage() は、ScreenReceiverListening スレッドではなく UI スレッドで呼び出されるはずですが、UI がフリーズするだけです。私を助けてください!

4

1 に答える 1

0

メソッドを非同期で呼び出す必要があります。

http://msdn.microsoft.com/de-de/library/2e08f6yc(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1

別の簡単な方法は、タイマーを使用することです。

 Private Sub ScreenListen()
        While ScreenReceiverClient.Connected = False
            ScreenReceiverServer.Start()
            ScreenReceiverClient = ScreenReceiverServer.AcceptTcpClient
        End While

        t1.Interval = 1
        t1.Start()
    End Sub

    Private WithEvents t1 As Windows.Forms.Timer

    Private Sub t1_Tick(sender As Object, e As EventArgs) Handles t1.Tick
        t1.Stop()
        ReceiveScreen()
    End Sub
于 2013-11-15T08:41:12.527 に答える