Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a start and stop button in my c# windows application. After pressing start button two For loops will be executed. On Stop button click i need too Quit those loops wherever the loop may be. But in my application after the entering the loop in Start button click i am unable to click any other button to stop the process.can any one explain the y is it happening lyk this?
Posted
Updated 6-Jan-15 0:37am
v2
Comments
Arjsrya 6-Jan-15 6:43am    
Have you tried using Threads?

 
Share this answer
 
Comments
BillWoodruff 6-Jan-15 8:55am    
+5
Abhinav S 6-Jan-15 11:40am    
Thank you.
Maciej Los 6-Jan-15 9:49am    
+5!
Abhinav S 6-Jan-15 11:40am    
Thank you Maciej.
Actually this problem is not with your loop or the business logic you're defining for your application. Instead in these frameworks that you're using there is only one thread-ed application which performs all of the logical executions and also makes the UI responsive. So, as long as those loops are running the UI thread won't be able to execute, making all of the UI (including buttons, TextBoxes) frozen.

What you need here, is to execute those loops in any other thread, which would run in the background. Thread can be an example of such process that can be executed in the background. You can use this to run the code in background (asynchronously) to let your application stay responsiveness (able to recieve clicks on Button, TextBox etc).

I have written another answer to depict the same condition and problem. You might be interested in reading that answer of mine. Do give this a read: How to safley give my function without making my main form stuck[^]

Once the UI is responsive, you can click on the button to terminate the loop using, break if you want to break the loop only, or stop the thread itself etc. It depends on your need.
 
Share this answer
 
v2
Comments
BillWoodruff 6-Jan-15 8:55am    
+5
Afzaal Ahmad Zeeshan 6-Jan-15 8:58am    
Thanks a lot Bill. :-)
Maciej Los 6-Jan-15 9:50am    
+5!
Afzaal Ahmad Zeeshan 6-Jan-15 9:58am    
Thanks a lot for your 5, Maciej. :-)
Hi,
Instead of buttons, you need to use treads for starting and stopping your operation.
Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900