----------------------------------------------------------------------------- Start a function running on this thread -----------------------------------------------------------------------------
| 75 | // Start a function running on this thread |
| 76 | //----------------------------------------------------------------------------- |
| 77 | bool ThreadImpl::Start |
| 78 | ( |
| 79 | Thread::pfnThreadProc_t _pfnThreadProc, |
| 80 | Event* _exitEvent, |
| 81 | void* _context |
| 82 | ) |
| 83 | { |
| 84 | // Create a thread to run the specified function |
| 85 | m_pfnThreadProc = _pfnThreadProc; |
| 86 | m_context = _context; |
| 87 | m_exitEvent = _exitEvent; |
| 88 | m_exitEvent->Reset(); |
| 89 | |
| 90 | create_task([this]() |
| 91 | { |
| 92 | m_bIsRunning = true; |
| 93 | try |
| 94 | { |
| 95 | m_pfnThreadProc(m_exitEvent, m_context); |
| 96 | } |
| 97 | catch (Platform::Exception^) |
| 98 | { |
| 99 | } |
| 100 | |
| 101 | m_bIsRunning = false; |
| 102 | // Let any watchers know that the thread has finished running. |
| 103 | m_owner->Notify(); |
| 104 | }); |
| 105 | return true; |
| 106 | } |
| 107 | |
| 108 | //----------------------------------------------------------------------------- |
| 109 | // <ThreadImpl::Sleep> |