Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

VB.NET Wieder mal Thraeding...

Empfohlene Antworten

Veröffentlicht

Hallo an Alle...

Ich starte in einem Modul einen Thread. Innerhalb des Threads möchte ich

eine Änderung an der Form vornhemen. Die Aktualisierung klappt jedoch nicht.

Hier der Quellcode:

Zuerst die Form:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

StarteThread()

End Sub

End Class

Hier das Modul:

Imports System.Threading

Module Module1

Delegate Sub DelegatedAktualisiereButtonText(ByVal strText As String)

Public Sub StarteThread()

Dim x As New Thread(AddressOf Hauptthread)

x.Start()

End Sub

Private Sub Hauptthread()

Dim s As New DelegatedAktualisiereButtonText(AddressOf AktualisiereButtonText)

s.Invoke("TEST")

End Sub

Private Sub AktualisiereButtonText(ByVal strText As String)

Form1.Button1.Text = strText

End Sub

End Module

Wo liegt mein Fehler ???

Danke vorab....

Hmm hab auch gerade gemerkt das es in .net 2008 bzw 2010 alles wieder ganz anders ist. Und man dieses invoke braucht.

Hier mal ein vielleicht ein Ansatz für dich. Es funktioniert zumindest.

Public Class Form1

    Public myThread As New System.Threading.Thread(AddressOf Hallo)



    Public Sub Hallo()


        Try

            While 1 = 1


                System.Threading.Thread.Sleep(1000)


                If Me.Button1.InvokeRequired Then

                    Button1.Invoke(New MethodInvoker(AddressOf Hallo))

                End If

                Me.Button1.Text = Now.ToString("yyyyMMddhhmmss")


                Application.DoEvents()

            End While


        Catch ex As Exception


        End Try

    End Sub


    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        myThread.Start()

    End Sub


End Class

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.