예제 #1
0
        public Loop()
        {
            IntPtr loopHandle = NativeMethods.Allocate(NativeMethods.uv_loop_size().ToInt32());

            try
            {
                int result = NativeMethods.uv_loop_init(loopHandle);
                NativeMethods.ThrowIfError(result);
            }
            catch
            {
                NativeMethods.FreeMemory(loopHandle);
                throw;
            }

            GCHandle gcHandle = GCHandle.Alloc(this, GCHandleType.Normal);

            ((uv_loop_t *)loopHandle)->data = GCHandle.ToIntPtr(gcHandle);
            _handle = loopHandle;
            if (Logger.InfoEnabled)
            {
                Logger.LoopAllocated(_handle);
            }
        }