473,320 Members | 1,825 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

multi threading error

hi, im writing a program with multiple threads, and in one of the secondary
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?

my code:

Private Sub ListenBegin()

Try

Dim ep As IPEndPoint

HomeIP = Net.Dns.GetHostEntry(Net.Dns.GetHostName).AddressL ist(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
Feb 27 '06 #1
2 1132

iwdu15 wrote:
hi, im writing a program with multiple threads, and in one of the secondary
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?


Short answer: Never invoke any method or property on a control created
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

Feb 27 '06 #2
thanks for the info, il keep that in mind! also thanks for the quick
response, it works great
--
-iwdu15
Feb 27 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: ajikoe | last post by:
Hello, Is anyone has experiance in running python code to run multi thread parallel in multi processor. Is it possible ? Can python manage which cpu shoud do every thread? Sincerely Yours,...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
0
by: Pawan Narula via DotNetMonster.com | last post by:
hi all, i'm using VB.NET and trying to code for contact management in a tree. all my contacts r saved in a text file and my C dll reads them one by one and sends to VB callback in a sync mode...
13
by: notregister | last post by:
my program have as many as 8 threads running at a same time. can different threads open a same file at the same time? let say thread1 open a file abc.txt at the same time with thread 2, both doing...
2
by: NiponW | last post by:
Hi, I have SQL SERVER 2000 SP4 Enterprise , Windows 2003 Enterprise on Xeon 4 Processors (now with multi-threading CPU) and I have questions which seem weirds to me (used to have the same...
1
by: vishal | last post by:
hi dear i am working on .net(1.1) web service and due to delay in response i made it multi threaded but when i passed a object in function which is called on a new thread, it is throwing...
6
by: Gina_Marano | last post by:
Hey All, I am using multiple child threads per main thread to download files. It sometimes appears as if the same file is being downloaded twice. I am using "lock". Am I using it correctly? Any...
0
ammoos
by: ammoos | last post by:
hi friends pls help me.. i got an assignment which i feel very difficult to me.. i dont have more knowledge about multi-threading in .net... the assignment details is below.... pls help me... i...
1
by: | last post by:
I have a multi threaded app that runs fine 99 percent of the time. However, sporadically, I receive error {Cannot evaluate expression because the current thread is in a stack overflow state.} at...
5
by: George Maicovschi | last post by:
As multi-threading is not built in PHP I've been using a hack letting the Apache server handle the multi-threading issues, but I'm really curious of other approaches to this issue. If anyone has...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.