Events are loaded and run on the main thread, and if the first event on the main thread is not finished, you come to the second event, just like other programs in the main thread, wait for the previous one to finish processing before processing the next or other program or event in the main thread.
The above is, I encapsulated an object myself, and in the object, I encapsulated an event myself.
I process data in the method of subscribing to events, such as the image annotation part,
Because the event I subscribed to was a read txt file, and my txt file had 50,000 lines, causing the event method to be triggered 50,000 times.
Then, when I ran the program, I found that my interface was in a state of suspended animation, and I knew that there must be a problem there.
I initially thought it was the manipulation of the UI controls in the method that caused fake death.
Then, step by step, it was found that when adding data to the set, it had already entered a state of suspended animation.
why??? Finally, I found out from the internet that the event is on the main thread, and if the first event is not processed, it will block the execution of the next event,
I generally understood what I ordered, to put it bluntly, 50,000 events caused the program to be blocked, and then I entered a state of suspended animation.
Solution:
For some simple events, which will not lead to the execution of a large number of event methods, can be written directly into the event method.
For a large number of event methods called, I hope you will open a thread to deal with it, such as: socket or httplistener, etc. (the amount of data is small and you can't see it, once the amount of data is large, haha, it will die directly)
|