How output msg from thread to label windows control ?
-
Is there anything i have to Consider it befor,output msg from thread to label windows control ? because i made code but it give me this exception->(Cross-thread operation not valid: Control 'Label1' accessed from a thread other than the thread it was created on.) i want to know why exactly this?,also what solution for it?
-
Is there anything i have to Consider it befor,output msg from thread to label windows control ? because i made code but it give me this exception->(Cross-thread operation not valid: Control 'Label1' accessed from a thread other than the thread it was created on.) i want to know why exactly this?,also what solution for it?
basically, Only the UI thread may update the UI, so you need to check whether you are on that thread, and if not delegate to it. InvokeRequired[^] Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
-
basically, Only the UI thread may update the UI, so you need to check whether you are on that thread, and if not delegate to it. InvokeRequired[^] Current blacklist svmilky - Extremely rude | FeRtoll - Rude personal emails | ironstrike1 - Rude & Obnoxious behaviour
-
Is there anything i have to Consider it befor,output msg from thread to label windows control ? because i made code but it give me this exception->(Cross-thread operation not valid: Control 'Label1' accessed from a thread other than the thread it was created on.) i want to know why exactly this?,also what solution for it?
' This is an example from msdn of microsoft Imports System Imports System.ComponentModel Imports System.Threading Imports System.Windows.Forms Public Class Form1 Inherits Form ' This delegate enables asynchronous calls for setting ' the text property on a TextBox control. Delegate Sub SetTextCallback([text] As String) ' This thread is used to demonstrate both thread-safe and ' unsafe ways to call a Windows Forms control. Private demoThread As Thread = Nothing ' This BackgroundWorker is used to demonstrate the ' preferred way of performing asynchronous operations. Private WithEvents backgroundWorker1 As BackgroundWorker Private textBox1 As TextBox Private WithEvents setTextUnsafeBtn As Button Private WithEvents setTextSafeBtn As Button Private WithEvents setTextBackgroundWorkerBtn As Button Private components As System.ComponentModel.IContainer = Nothing Public Sub New() InitializeComponent() End Sub Protected Overrides Sub Dispose(disposing As Boolean) If disposing AndAlso Not (components Is Nothing) Then components.Dispose() End If MyBase.Dispose(disposing) End Sub ' This event handler creates a thread that calls a ' Windows Forms control in an unsafe way. Private Sub setTextUnsafeBtn_Click( _ ByVal sender As Object, _ ByVal e As EventArgs) Handles setTextUnsafeBtn.Click Me.demoThread = New Thread( _ New ThreadStart(AddressOf Me.ThreadProcUnsafe)) Me.demoThread.Start() End Sub ' This method is executed on the worker thread and makes ' an unsafe call on the TextBox control. Private Sub ThreadProcUnsafe() Me.textBox1.Text = "This text was set unsafely." End Sub ' This event handler creates a thread that calls a ' Windows Forms control in a thread-safe way. Private Sub setTextSafeBtn_Click( _ ByVal sender As Object, _ ByVal e As EventArgs) Handles setTextSafeBtn.Click Me.demoThread = New Thread( _ New ThreadStart(AddressOf Me.ThreadProcSafe)) Me.demoThread.Start() End Sub ' This method is executed on the worker thread and makes ' a thread-safe call on the TextBox control. Private Sub ThreadProcSafe() Me.SetText("This text was set safely.") End Sub ' This method demonstrates a pattern for making thread-safe ' calls on a Windows Forms control. '
-
' This is an example from msdn of microsoft Imports System Imports System.ComponentModel Imports System.Threading Imports System.Windows.Forms Public Class Form1 Inherits Form ' This delegate enables asynchronous calls for setting ' the text property on a TextBox control. Delegate Sub SetTextCallback([text] As String) ' This thread is used to demonstrate both thread-safe and ' unsafe ways to call a Windows Forms control. Private demoThread As Thread = Nothing ' This BackgroundWorker is used to demonstrate the ' preferred way of performing asynchronous operations. Private WithEvents backgroundWorker1 As BackgroundWorker Private textBox1 As TextBox Private WithEvents setTextUnsafeBtn As Button Private WithEvents setTextSafeBtn As Button Private WithEvents setTextBackgroundWorkerBtn As Button Private components As System.ComponentModel.IContainer = Nothing Public Sub New() InitializeComponent() End Sub Protected Overrides Sub Dispose(disposing As Boolean) If disposing AndAlso Not (components Is Nothing) Then components.Dispose() End If MyBase.Dispose(disposing) End Sub ' This event handler creates a thread that calls a ' Windows Forms control in an unsafe way. Private Sub setTextUnsafeBtn_Click( _ ByVal sender As Object, _ ByVal e As EventArgs) Handles setTextUnsafeBtn.Click Me.demoThread = New Thread( _ New ThreadStart(AddressOf Me.ThreadProcUnsafe)) Me.demoThread.Start() End Sub ' This method is executed on the worker thread and makes ' an unsafe call on the TextBox control. Private Sub ThreadProcUnsafe() Me.textBox1.Text = "This text was set unsafely." End Sub ' This event handler creates a thread that calls a ' Windows Forms control in a thread-safe way. Private Sub setTextSafeBtn_Click( _ ByVal sender As Object, _ ByVal e As EventArgs) Handles setTextSafeBtn.Click Me.demoThread = New Thread( _ New ThreadStart(AddressOf Me.ThreadProcSafe)) Me.demoThread.Start() End Sub ' This method is executed on the worker thread and makes ' a thread-safe call on the TextBox control. Private Sub ThreadProcSafe() Me.SetText("This text was set safely.") End Sub ' This method demonstrates a pattern for making thread-safe ' calls on a Windows Forms control. '