Today Study

xiaoxiao2021-03-06  38

Multi-threaded programming, incident imports system.threadingpublic class counter public max as integer = 0 public evenet donecounting (Byval Number AS INTEGER)

Sub Count () DIM TOTAL AS INTEGER = 0 for i as integer = 0 to 10 for loopIndex as integer = 1 to max

total = 1 Next loopIndex Thread.Sleep (500) RaiseEvent DoneCounting (total) 'If this is a thread, this may trigger event Next i End SubEnd Class Dim thread1 As New Thread (AddressOf counterObject.count) AddHandler counterObject.DoneCounting, Addressof A 'then handles the event, A is the address of the processing function DIM Thread1 as new thread (addressof counterbject.count)' Define thread counterbject.max = 10000 '... After some assignment operation, thread1.start starts Thread1.start () Note: The Windows program measurement time interval is greater than milliseconds, so that SLEEP (1) and sleep (10) will provide the same time interval. When some thread is still executed, I closed the form, but there is a hand of the text box in the thread, and the result is an exception. Private sub a (byval x as integer) Try TextBox1.AppendText (x.tostring & chr (13) & chr (10)) Catch exception messageBox.show (ex. amount) End end Sub will talk about multiple conversations Box until the thread exits, the application will exit. This is the result of the closing button of some forms. Application.exit () is also the same. So, how can I simply turn off the app when there is a thread run? If you use Join, the program will hang until the thread is completed or interrupted.

转载请注明原文地址:https://www.9cbs.com/read-65635.html

New Post(0)