In my program i'm starting
private void button1_Click(object sender, EventArgs e)
for( int i = 0; i < var; i++)
private void button2_Click(object sender, EventArgs e)
You cannot do that, because the loop in
button1_Click event handler will be holding the UI thread. Your user interface will not respond to any event, showing hourglass icon, until the loop is over. This means that
button2_Click cannot be entered until
button1_Click has completed.
You need to replace the long-running loop from the event handler with something that runs outside the UI thread. For example, you can use
Tasks, which can be cancelled using
CancellationToken (related Q&A).