All pastes #526694 Raw Edit

Mine

public text v1 · immutable
#526694 ·published 2007-05-31 22:29 UTC
rendered paste body
        private ManualResetEvent m_Event = new ManualResetEvent ();
        public void StartThread() {
            ThreadPool.QueueUserWorkItem (new WaitCallback (ThreadRun), ar);
        }

        private void ThreadRun () {
            while(true) {
                // do work, do work
                if(m_Event.WaitOne(0)) {
                    // time to exit
                }
            }
        }

        private void OnButtonClick() {
            m_Event.Set (); // Tell the thread it's time to exit gracefully;
        }