showing the whole code here would be too big and unimportant, so it's a question based on a pseudo-code.
The application on form load initialise and start 4 background workers
Consider the code is not just dealing with integer but one thread gets a string, breaks it down to parts, converts them to integers or doubles, whilst other threads read those values and put them into labels or datagridviews.
Questions:
- will it at some random time give me an error because more than one thread is trying to access the variable?
- the code is compiled and installed in a client machine, what will be the behaviour of this machine whenever the error occurs? app freezes and have to shut from task manager? machine freezes and you have to pull the power plug? some .net framework pop-up error will come up?
thanks.
The application on form load initialise and start 4 background workers
VB.NET:
Dim myInt as integer = 0
Private Sub ThreadsWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) _
Handles BGThread_1.DoWork, _
BGThread_2.DoWork, _
BGThread_3.DoWork, _
BGThread_4.DoWork
dim x as integer
dim y as integer = RandomInt
While(True)
x = myInt
' some math with x and y
myInt = x*y
Thread.Sleep(RandomBetween(500, 1500))
End While
End Sub
Consider the code is not just dealing with integer but one thread gets a string, breaks it down to parts, converts them to integers or doubles, whilst other threads read those values and put them into labels or datagridviews.
Questions:
- will it at some random time give me an error because more than one thread is trying to access the variable?
- the code is compiled and installed in a client machine, what will be the behaviour of this machine whenever the error occurs? app freezes and have to shut from task manager? machine freezes and you have to pull the power plug? some .net framework pop-up error will come up?
thanks.
Last edited: