I have a local thread that starts when a button is clicked from the main thread. His name
"RegistrationThread". Now I want to stop this thread on another click event of the stop button. how
I stop "RegistrationThread", which is a local thread, and I cannot access this thread by its
name. If I get "RegistrationThread" then it can be paused. How to do it?
. , . , . -. - , , .
public class YourForm : Form { private volatile bool m_Stop = false; private void StartButton_Click(object sender, EventArgs e) { var thread = new Thread( () => { while (...) { // Periodically poll the m_Stop flag. if (m_Stop) { break; } } }); thread.Start(); } private void StopButton_Click(object sender, EventArgs e) { m_Stop = true; } }
, Thread, Abort .
Thread
Abort
, , Thread.Name . ?
() .net, .
Thread.Abort. , , , . , MSDN , Abort() "" . , API , .
, - , . , .net (, ), . microsoft Thread.Suspend .
, , , , .
Source: https://habr.com/ru/post/1761716/More articles:как отображать текст в UIWebVIew - objective-cDataGridView rows cannot change background color during initialization - c #Как убить службу Windows с пробелом в имени с помощью taskkill в пакетном файле - service.NET socket lock processing timeout - c #Convert type string to object type - c #What is session.bug_compat_42 and session.bug_compat_warn? - phplate binding in linq - vb.netperformance tuning for JSF - javaWinForm: представляет один элемент ListBox в инструкции foreach - winformsMySQL Float Type - sqlAll Articles