|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
multi threading errorthreads, i need to access the main form...but the code i wrote throws errors saying i cant do this. is there anyway i can simply change the text on the main form from another thread? my code: Private Sub ListenBegin() Try Dim ep As IPEndPoint HomeIP = Net.Dns.GetHostEntry(Net.Dns.GetHostName).AddressList(0) ep = New IPEndPoint(HomeIP, PortNumber) ListenSocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) ListenSocket.Bind(ep) ListenSocket.Listen(1) ListenSocket.BeginAccept(AddressOf ListenCallBack, Nothing) Catch ex As Exception Call WriteErrors(ex.Message, "ListenBegin") Finally SyncLock Me ''error here Me.Text = HomeIP.ToString End SyncLock End Try End Sub -- -iwdu15 iwdu15 wrote:
> hi, im writing a program with multiple threads, and in one of the secondary Short answer: Never invoke any method or property on a control created> threads, i need to access the main form...but the code i wrote throws errors > saying i cant do this. is there anyway i can simply change the text on the > main form from another thread? on another thread Background reading: <http://yoda.arachsys.com/csharp/threads/winforms.shtml> Quick fix: change SyncLock Me Me.Text = HomeIP.ToString End SyncLock to Me.Invoke(New StringParameterDelegate(AddressOf TextSetter), _ New Object() {HomeIP.ToString}) add Delegate Sub StringParameterDelegate(ByVal value As String) at form level and add Private Sub TextSetter(ByVal value As String) Me.Text = value End Sub -- Larry Lard thanks for the info, il keep that in mind! also thanks for the quick
response, it works great -- -iwdu15
Did we lose the RadioCheck property on menuitems
How does the community rate .NET 2005 vs. .NET 2003? List.Add method overwriting collectionbase? Webapplications quits without matter in ASP.NET 2.0 Ado.net to excel ? Listbox controls The variable 'GroupBox1' is either undeclared or was never assigned. List all public properties of a Class ? i love reflection:) Perfomance test |
|||||||||||||||||||||||