• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# SafeHandles.SafeWaitHandle类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Microsoft.Win32.SafeHandles.SafeWaitHandle的典型用法代码示例。如果您正苦于以下问题:C# SafeWaitHandle类的具体用法?C# SafeWaitHandle怎么用?C# SafeWaitHandle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SafeWaitHandle类属于Microsoft.Win32.SafeHandles命名空间,在下文中一共展示了SafeWaitHandle类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: CanlibWaitHandle

 public CanlibWaitHandle(object we)
 {
     uint theHandle = (uint) we;
       IntPtr pointer = new IntPtr((long) theHandle);
       SafeWaitHandle swHandle = new SafeWaitHandle(pointer, true);
       base.SafeWaitHandle = swHandle;
 }
开发者ID:mc01104,项目名称:CTR,代码行数:7,代码来源:CanlibWaitHandle.cs


示例2: Semaphore

        public Semaphore(int initialCount, int maximumCount, string name)
        {
            if (initialCount < 0)
            {
                throw new ArgumentOutOfRangeException("initialCount", SR.ArgumentOutOfRange_NeedNonNegNumRequired);
            }

            if (maximumCount < 1)
            {
                throw new ArgumentOutOfRangeException("maximumCount", SR.ArgumentOutOfRange_NeedPosNum);
            }

            if (initialCount > maximumCount)
            {
                throw new ArgumentException(SR.Argument_SemaphoreInitialMaximum);
            }

            if (null != name && MAX_PATH < name.Length)
            {
                throw new ArgumentException(SR.Argument_WaitHandleNameTooLong);
            }
            SafeWaitHandle myHandle = new SafeWaitHandle(Interop.mincore.CreateSemaphoreEx(IntPtr.Zero, initialCount, maximumCount, name, 0, (uint)(Interop.Constants.SemaphoreModifyState | Interop.Constants.Synchronize)), true);

            if (myHandle.IsInvalid)
            {
                int errorCode = (int)Interop.mincore.GetLastError();

                if (null != name && 0 != name.Length && Interop.mincore.Errors.ERROR_INVALID_HANDLE == errorCode)
                    throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name));

                throw ExceptionFromCreationError(errorCode, name);
            }

            SafeWaitHandle = myHandle;
        }
开发者ID:tijoytom,项目名称:corert,代码行数:35,代码来源:Semaphore.cs


示例3: Thread

		public static UInt64 Thread(SafeWaitHandle threadHandle)
		{
			UInt64 cycleTime;
			if (!QueryThreadCycleTime(threadHandle, out cycleTime))
				throw new Win32Exception();
			return cycleTime;
		}
开发者ID:zhangz,项目名称:Toolbox,代码行数:7,代码来源:CodeTimer.cs


示例4: Process

		public static UInt64 Process(SafeWaitHandle processHandle)
		{
			UInt64 cycleTime;
			if (!QueryProcessCycleTime(processHandle, out cycleTime))
				throw new Win32Exception();
			return cycleTime;
		}
开发者ID:zhangz,项目名称:Toolbox,代码行数:7,代码来源:CodeTimer.cs


示例5: SetWaitableTimer

 public static extern bool SetWaitableTimer(
     SafeWaitHandle hTimer,
     [In] ref long pDueTime,
     int lPeriod,
     IntPtr pfnCompletionRoutine,
     IntPtr lpArgToCompletionRoutine,
     bool fResume);
开发者ID:narunaru0,项目名称:Umanushi,代码行数:7,代码来源:WakeUPTimer.cs


示例6: RegNotifyChangeKeyValue

 public static extern int RegNotifyChangeKeyValue(
     UIntPtr hKey,
     bool bWatchSubtree,
     uint dwNotifyFilter,
     SafeWaitHandle hEvent,
     bool fAsynchronous
     );
开发者ID:gmilazzoitag,项目名称:OpenLiveWriter,代码行数:7,代码来源:Advapi32.cs


示例7: SoundCaptureBase

        public SoundCaptureBase(SoundCaptureDevice device)
        {
            this.device = device;

            positionEvent = new AutoResetEvent(false);
            positionEventHandle = positionEvent.SafeWaitHandle;
            terminated = new ManualResetEvent(true);
        }
开发者ID:notmasteryet,项目名称:FftGuitarTuner,代码行数:8,代码来源:SoundCaptureBase.cs


示例8: CycleTime

 /// <summary>
 /// Initializes a new instance of the CycleTime class.
 /// </summary>
 /// <param name="trackingThreadTime">
 /// True if you want to track the current thread time. False for the 
 /// process as a whole.
 /// </param>
 /// <param name="handle">
 /// The handle to the process for observing.
 /// </param>
 private CycleTime(Boolean trackingThreadTime, SafeWaitHandle handle)
 {
     this.trackingThreadTime = trackingThreadTime;
     this.handle = handle;
     this.startCycleTime = this.trackingThreadTime
                         ? Thread()
                         : Process(this.handle);
 }
开发者ID:nayato,项目名称:microbenchmarks,代码行数:18,代码来源:Wintellect.cs


示例9: Process

 /// <summary>
 ///     Retrieves the sum of the cycle time of all threads of the specified
 ///     process.
 /// </summary>
 public static ulong Process(SafeWaitHandle processHandle)
 {
     ulong cycleTime;
     if (!QueryProcessCycleTime(processHandle, out cycleTime))
     {
         throw new Win32Exception();
     }
     return cycleTime;
 }
开发者ID:RabbitTeam,项目名称:DotNetty,代码行数:13,代码来源:CycleTime.cs


示例10: Thread

 /// <summary>
 ///     Retrieves the cycle time for the specified thread.
 /// </summary>
 public static ulong Thread(SafeWaitHandle threadHandle)
 {
     ulong cycleTime;
     if (!QueryThreadCycleTime(threadHandle, out cycleTime))
     {
         throw new Win32Exception();
     }
     return cycleTime;
 }
开发者ID:RabbitTeam,项目名称:DotNetty,代码行数:12,代码来源:CycleTime.cs


示例11: ResetEvent

		public static bool ResetEvent (SafeWaitHandle handle)
		{
			bool release = false;
			try {
				handle.DangerousAddRef (ref release);
				return ResetEvent_internal (handle.DangerousGetHandle ());
			} finally {
				if (release)
					handle.DangerousRelease ();
			}
		}
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:11,代码来源:NativeEventCalls.cs


示例12: AbsoluteTimer

        public WaitHandle AbsoluteTimer(DateTimeOffset expireAt)
        {
            var handle = CreateWaitableTimer(IntPtr.Zero, true, null);

            var dueTime = expireAt.ToUniversalTime().ToFileTime();

            SetWaitableTimer(handle, ref dueTime, 0, IntPtr.Zero, IntPtr.Zero, false);

            var safeHandle = new SafeWaitHandle(handle, true);

            return new TimerWaitHandle(safeHandle);
        }
开发者ID:hash,项目名称:trigger.net,代码行数:12,代码来源:Win32Native.cs


示例13: ProcessInfo

        public ProcessInfo(
            Process ps, 
            ProcessInformation psi)
        {
            if (null == ps)
            {
                throw new ArgumentNullException("ps");
            }

            this.ps = ps;
            this.mainThreadHandle = new SafeWaitHandle(
                psi.hThread, 
                true);
        }
开发者ID:gregjhogan,项目名称:ApplicationInsights-server-dotnet,代码行数:14,代码来源:ProcessInfo.cs


示例14: ByteRangeDownloader

        internal ByteRangeDownloader(Uri requestedUri, string tempFileName, SafeWaitHandle eventHandle)
            : this(requestedUri, eventHandle)
        {
            if (tempFileName == null)
            {
                throw new ArgumentNullException("tempFileName");
            }

            if (tempFileName.Length <= 0)
            {
                throw new ArgumentException(SR.Get(SRID.InvalidTempFileName), "tempFileName");
            }

            _tempFileStream = File.Open(tempFileName, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:15,代码来源:ByteRangeDownloader.cs


示例15: EventWaitHandle

        public EventWaitHandle(bool initialState, EventResetMode mode, string name)
        {
            if(null != name && System.IO.Path.MAX_PATH < name.Length)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_WaitHandleNameTooLong",name));
            }
            Contract.EndContractBlock();
            
            SafeWaitHandle _handle = null;
#if MONO
            int errorCode;
#endif
            switch(mode)
            {
                case EventResetMode.ManualReset:
#if MONO
                    _handle = new SafeWaitHandle (NativeEventCalls.CreateEvent_internal (true, initialState, name, out errorCode), true);
#else
                    _handle = Win32Native.CreateEvent(null, true, initialState, name);
#endif
                    break;
                case EventResetMode.AutoReset:
#if MONO
                    _handle = new SafeWaitHandle (NativeEventCalls.CreateEvent_internal (false, initialState, name, out errorCode), true);
#else
                    _handle = Win32Native.CreateEvent(null, false, initialState, name);
#endif
                    break;

                default:
                    throw new ArgumentException(Environment.GetResourceString("Argument_InvalidFlag",name));
            };
                
            if (_handle.IsInvalid)
            {
#if !MONO
                int errorCode = Marshal.GetLastWin32Error();
#endif
            
                _handle.SetHandleAsInvalid();
                if(null != name && 0 != name.Length && Win32Native.ERROR_INVALID_HANDLE == errorCode)
                    throw new WaitHandleCannotBeOpenedException(Environment.GetResourceString("Threading.WaitHandleCannotBeOpenedException_InvalidHandle",name));

                __Error.WinIOError(errorCode, name);
            }
            SetHandleInternal(_handle);
        }
开发者ID:ItsVeryWindy,项目名称:mono,代码行数:47,代码来源:eventwaithandle.cs


示例16: Semaphore

        public Semaphore(int initialCount, int maximumCount, string name)
        {
            if (initialCount < 0)
            {
                throw new ArgumentOutOfRangeException("initialCount", SR.GetString(SR.ArgumentOutOfRange_NeedNonNegNumRequired));
            }

            if (maximumCount < 1)
            {
                throw new ArgumentOutOfRangeException("maximumCount", SR.GetString(SR.ArgumentOutOfRange_NeedPosNum));
            }

            if (initialCount > maximumCount)
            {
                throw new ArgumentException(SR.GetString(SR.Argument_SemaphoreInitialMaximum));
            }

            if(null != name && MAX_PATH < name.Length)
            {
                throw new ArgumentException(SR.GetString(SR.Argument_WaitHandleNameTooLong));
            }

#if MONO
            int errorCode;
            var myHandle = new SafeWaitHandle (CreateSemaphore_internal (initialCount, maximumCount, name, out errorCode), true);
#else
            SafeWaitHandle   myHandle = SafeNativeMethods.CreateSemaphore(null, initialCount, maximumCount, name);
#endif
            
            if (myHandle.IsInvalid)
            {
#if !MONO
                int errorCode = Marshal.GetLastWin32Error(); 
#endif

                if(null != name && 0 != name.Length && NativeMethods.ERROR_INVALID_HANDLE == errorCode)
                    throw new WaitHandleCannotBeOpenedException(SR.GetString(SR.WaitHandleCannotBeOpenedException_InvalidHandle,name));
               
#if MONO
                InternalResources.WinIOError(errorCode, "");
#else
                InternalResources.WinIOError();
#endif
            }
            this.SafeWaitHandle = myHandle;
        }
开发者ID:sushihangover,项目名称:playscript,代码行数:46,代码来源:semaphore.cs


示例17: EventWaitHandle

        public EventWaitHandle(bool initialState, EventResetMode mode, string name)
        {
            if (null != name)
            {
                if (((int)Interop.Constants.MaxPath) < name.Length)
                {
                    throw new ArgumentException(SR.Format(SR.Argument_WaitHandleNameTooLong, name));
                }
            }
            Contract.EndContractBlock();

            uint eventFlags = initialState ? (uint)Interop.Constants.CreateEventInitialSet : 0;

            IntPtr unsafeHandle;
            switch (mode)
            {
                case EventResetMode.ManualReset:
                    eventFlags |= (uint)Interop.Constants.CreateEventManualReset;
                    break;

                case EventResetMode.AutoReset:
                    break;

                default:
                    throw new ArgumentException(SR.Format(SR.Argument_InvalidFlag, name));
            };

            unsafeHandle = Interop.mincore.CreateEventEx(IntPtr.Zero, name, eventFlags, (uint)Interop.Constants.EventAllAccess);
            int errorCode = (int)Interop.mincore.GetLastError();
            SafeWaitHandle _handle = new SafeWaitHandle(unsafeHandle, true);

            if (_handle.IsInvalid)
            {
                _handle.SetHandleAsInvalid();
                if (null != name && 0 != name.Length && Interop.mincore.Errors.ERROR_INVALID_HANDLE == errorCode)
                    throw new WaitHandleCannotBeOpenedException(SR.Format(SR.Threading_WaitHandleCannotBeOpenedException_InvalidHandle, name));

                throw ExceptionFromCreationError(errorCode, name);
            }
            SafeWaitHandle = _handle;
        }
开发者ID:tijoytom,项目名称:corert,代码行数:41,代码来源:EventWaitHandle.cs


示例18: bgWorker_DoWork

        private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            long waketime = (long)e.Argument;

            using (handle = CreateWaitableTimer(IntPtr.Zero, true, this.GetType().Assembly.GetName().Name.ToString() + "Timer"))
            {
                if (SetWaitableTimer(handle, ref waketime, 0, IntPtr.Zero, IntPtr.Zero, true))
                {
                    using (wh = new EventWaitHandle(false, EventResetMode.AutoReset))
                    {
                        wh.SafeWaitHandle = handle;
                        wh.WaitOne();
                    }
                }
                else
                {
                    throw new Win32Exception(Marshal.GetLastWin32Error());
                }
            }
            wh = null;
        }
开发者ID:valtzu,项目名称:kake,代码行数:21,代码来源:WakeUP.cs


示例19: Persist

 internal void Persist(SafeWaitHandle handle)
 {
     base.WriteLock();
     try
     {
         AccessControlSections accessControlSectionsFromChanges = this.GetAccessControlSectionsFromChanges();
         if (accessControlSectionsFromChanges != AccessControlSections.None)
         {
             bool flag;
             bool flag2;
             base.Persist(handle, accessControlSectionsFromChanges);
             base.AccessRulesModified = flag = false;
             base.AuditRulesModified = flag2 = flag;
             base.OwnerModified = base.GroupModified = flag2;
         }
     }
     finally
     {
         base.WriteUnlock();
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:21,代码来源:EventWaitHandleSecurity.cs


示例20: DuplicateHandle

		public static bool DuplicateHandle(HandleRef hSourceProcessHandle, SafeHandle hSourceHandle, HandleRef hTargetProcess,
			out SafeWaitHandle targetHandle, int dwDesiredAccess, bool bInheritHandle, int dwOptions)
		{
			bool release = false;
			try {
				hSourceHandle.DangerousAddRef (ref release);

				MonoIOError error;
				IntPtr nakedTargetHandle;
				bool ret = MonoIO.DuplicateHandle (hSourceProcessHandle.Handle, hSourceHandle.DangerousGetHandle (), hTargetProcess.Handle,
					out nakedTargetHandle, dwDesiredAccess, bInheritHandle ? 1 : 0, dwOptions, out error);

				if (error != MonoIOError.ERROR_SUCCESS)
					throw MonoIO.GetException (error);

				targetHandle = new SafeWaitHandle (nakedTargetHandle, true);
				return ret;
			} finally {
				if (release)
					hSourceHandle.DangerousRelease ();
			}
		}
开发者ID:BogdanovKirill,项目名称:mono,代码行数:22,代码来源:NativeMethods.cs



注:本文中的Microsoft.Win32.SafeHandles.SafeWaitHandle类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# SafeHandles.SafeX509Handle类代码示例发布时间:2022-05-26
下一篇:
C# SafeHandles.SafeSslHandle类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap