Why you are not able to click Form1 Cross sign while code is running?

Herry Markowitz

Well-known member
Joined
Oct 22, 2015
Messages
46
Programming Experience
1-3
Hi forummates,
1- Make Windows Form Application.
2- Put Button1 on Form1.
3- Run following code.
VB.NET:
Public Class Form1    
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        For i = 1 To 10000000000
            i = i + 1
        Next
    End Sub
End Class
4- While above code is running try to click Cross sign of Form1. (See that you are not able to click Cross sign of Form1 while above code is running)
Question: Why you are not able to click Cross sign of Form1 while code is running?
How does user stop running of application without waiting it is completed? Ctrl+Alt+Delete or something else?
 
Last edited:
While UI thread is busy processing code it can not also process other code, such as events and windows messages.
That is the reason you should never add code that will or may prevent UI thread from normal operation, such code must be performed on a secondary thread.
 
The answer is you don't write code like that, you employ multi-threading.
 
Back
Top