I have a problem with multithreading.
I am doing a project in which we have a train, rail crossing and a car carriage, and if necessary, rail crossings and car stops. The three things are on different threads, there are 2 buttons, a train starts moving, the other creates a new pictureboxy car.
To move the train, I simply use to loop
using the
invoke
location of the picture box changes the location of the rail crossing bus train. Checks and when the train is in a specific place, the red changes.
Creating a car looks like this:
Private Zero Operation 1 () (this.inbineWolk (method choice) () {PictureBox a = New Picture Box () ; A.Location = new point (333, 361); a.BackColor = Color.Black; a.Size = new size (20, 37); Add Control (A);})}}
The car has been created and it is okay. Now I would like to move a car with the loop in operation 1 ()
:
Private Zero Operation 1 () {this.BeginInvoke (MethodInvoker) representative) {PictureBox a = New Picture Box (); a Location = New point (333, 361); a.BackColor = Color.Black; a.Size = new size (20, 37); Controls.Add (a); Int i = 0; i <140; i + +) {A.Location = New point (a.Location.X, a.Location.Y - 3); Thread Sleep (50);}}); }
But when this car starts, then it disappears, if the second thread is going on, then it stops and until the loop ends, where is the problem? I hope someone can help me as soon as possible.
Instead of using it. To update the UI, another thread encapsulate your objects into one square and read the status from that class.
When you invite UI to update this way, the thread is handed over to the UI thread and freezes it all at all times, it's completely nonsense :)
Comments
Post a Comment