Click here to Skip to main content
15,899,475 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hey, i made a start button and its to start the action or the job i want from my program to do
and there is a stop button to but if my program working i can't access to form to press stop button
is there anyway to make access to form while working possible ?

What I have tried:

how to stop threading while program working ?
Posted
Updated 22-Jun-17 0:00am
Comments
F-ES Sitecore 22-Jun-17 6:14am    
This is quite a fundamental aspect of forms programming, it helps to understand the concept of threads and the fact that the UI updates on the "main" thread and if you are using that thread to "do work" then the UI can't function at the same time so no form updates and no click events of buttons.

As alluded to in the solutions you need to do the work on a separate thread. This will become more complex if that thread needs to update the UI in any way as background threads can't update the UI directly as it is running on a different thread.

Anyway, have a look at this, it explains all these things with code samples

https://msdn.microsoft.com/en-us/library/ms951089.aspx

Not sure if there are more up-to-date ways of dealing with this stuff.

Take a look at the BackgroundWorker class
MSDN BackgroundWorker Class (System.ComponentModel)[^]
The link will provide you with the class reference and examples

Kind Regards
 
Share this answer
 
Comments
Ilyas Zahir 22-Jun-17 0:16am    
thanks <3
an0ther1 22-Jun-17 0:20am    
No worries, if this resolves your question please mark it as an answer

Kind Regards
Instead of using a Background Worker thread, which is sort-of old-school, though it does work quite well admittedly, You should consider using a 'Task'

Tasks in .net can be awaited and cancelled pretty easily

Task Cancellation | Microsoft Docs[^]
 
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