Ejemplo n.º 1
0
        public void Start()
        {
            var func     = Marshal.GetFunctionPointerForDelegate(_threadFuncDelegate);
            var handlePt = GCHandle.Alloc(_threadParameter);
            var ptrPt    = GCHandle.ToIntPtr(handlePt);

            uint lpThreadId;

            Handle = WinApiHelper.CreateThread(IntPtr.Zero, 0, func, ptrPt, 0, out lpThreadId);

            WinApiHelper.SetThreadPriority(Handle, (int)_startPriorityLevel);
            Id = lpThreadId;

            DiagnosticHelper.SetThreadAffinity(Id);
        }
Ejemplo n.º 2
0
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            if (disposing)
            {
                _threadFuncDelegate = null;
            }

            WinApiHelper.WaitForSingleObject(Handle, 10000);
            WinApiHelper.CloseHandle(Handle);

            _disposed = true;
        }