当前位置: 首页>>代码示例>>C#>>正文


C# Threading.EventWaitHandle类代码示例

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


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

示例1: Main

        public static void Main(string[] args)
        {

            var done = new EventWaitHandle(false, EventResetMode.AutoReset);

            var yield = new Thread(
                new ParameterizedThreadStart(
                    data =>
                    {
                        Console.WriteLine(new { data });

                        done.Set();
                    }
                )
            );

            Console.WriteLine("before wait " + DateTime.Now);

            // Additional information: Thread has not been started.
            done.WaitOne(2100);

            Console.WriteLine("after wait " + DateTime.Now);

            yield.Start(new { foo = "bar" });

            done.WaitOne();

            Console.WriteLine("done");

            CLRProgram.CLRMain();
        }
开发者ID:exaphaser,项目名称:JSC-Cross-Compiler,代码行数:31,代码来源:Program.cs

示例2: DebuggerStart

    private void DebuggerStart(EventWaitHandle startWaitHandle, Func<ProcessInformation> processCreator, Action<ProcessInformation> callback, Action<Exception> errorCallback) {
      try {
        _debuggerThread = Thread.CurrentThread;
        // Note: processCreator is responsible for creating the process in DEBUG mode.
        // Note: If processCreator throws an exception after creating the
        // process, we may end up in a state where we received debugging events
        // without having "_processInformation" set. We need to be able to deal
        // with that.
        _processInformation = processCreator();
        callback(_processInformation);
      }
      catch (Exception e) {
        errorCallback(e);
        return;
      }
      finally {
        startWaitHandle.Set();
      }

      _running = true;
      try {
        DebuggerLoop();
      }
      finally {
        _running = false;
      }
    }
开发者ID:mbbill,项目名称:vs-chromium,代码行数:27,代码来源:DebuggerThread.cs

示例3: ActivateThreaded

		/// <summary>
		/// Turns this panel into multi-threaded mode.
		/// This will sort of glitch out other gdi things on the system, but at least its fast...
		/// </summary>
		public void ActivateThreaded()
		{
			ewh = new EventWaitHandle(false, EventResetMode.AutoReset);
			threadPaint = new Thread(PaintProc);
			threadPaint.IsBackground = true;
			threadPaint.Start();
		}
开发者ID:henke37,项目名称:BizHawk,代码行数:11,代码来源:ViewportPanel.cs

示例4: ResponseListener

 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="session"></param>
 public ResponseListener(O2GSession session)
 {
     mRequestID = string.Empty;
     mResponse = null;
     mSyncResponseEvent = new EventWaitHandle(false, EventResetMode.AutoReset);
     mSession = session;
 }
开发者ID:fxcmapidavid,项目名称:Forex-Connect,代码行数:11,代码来源:ResponseListener.cs

示例5: Main

        public static void Main(string[] args)
        {
            var dir = @"c:\tmp";
            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            ewh = new EventWaitHandle(false, EventResetMode.ManualReset);

            for (int i = 0; i <= 10; i++)
            {
                var t = new Thread(ThreadProc);
                t.Start(i);
                Console.WriteLine("Tread {0} started", i);
            }

            watcher = new FileSystemWatcher()
            {
                Path = dir,
                IncludeSubdirectories = false,
                EnableRaisingEvents = true,
            };

            watcher.Created += (sender, eventArgs) =>
            {
                 ewh.Set();
            };

            Console.WriteLine("Press any key....");
            Console.ReadLine();
        }
开发者ID:microcourse,项目名称:comda,代码行数:32,代码来源:Program.cs

示例6: HttpChannelListenerEntry

		public HttpChannelListenerEntry (ChannelDispatcher channel, EventWaitHandle waitHandle)
		{
			ChannelDispatcher = channel;
			WaitHandle = waitHandle;
			ContextQueue = new Queue<HttpContextInfo> ();
			RetrieverLock = new object ();
		}
开发者ID:nickchal,项目名称:pash,代码行数:7,代码来源:HttpChannelListenerEntry.cs

示例7: EndProfile

 private void EndProfile(RequestItem pending, IRestResponse response, EventWaitHandle signal)
 {
     TimeSpan elapsed = pending.Elapsed;
     network.Profile(response, pending.Started, elapsed);
     network.ProfilePendingRemove(pending);
     signal.Set();
 }
开发者ID:bevacqua,项目名称:Swarm,代码行数:7,代码来源:VirtualUser.cs

示例8: FetchSchema

        /// <summary>
        /// Fetches the Tf2 Item schema.
        /// </summary>
        /// <param name="apiKey">The API key.</param>
        /// <returns>A  deserialized instance of the Item Schema.</returns>
        /// <remarks>
        /// The schema will be cached for future use if it is updated.
        /// </remarks>
        public static Schemazh FetchSchema()
        {
            var url = SchemaApiUrlBase;

            // just let one thread/proc do the initial check/possible update.
            bool wasCreated;
            var mre = new EventWaitHandle(false,
                EventResetMode.ManualReset, SchemaMutexName, out wasCreated);

            // the thread that create the wait handle will be the one to
            // write the cache file. The others will wait patiently.
            if (!wasCreated)
            {
                bool signaled = mre.WaitOne(10000);

                if (!signaled)
                {
                    return null;
                }
            }

            HttpWebResponse response = Drop.SteamWeb.Request(url, "GET");

            DateTime schemaLastModified = DateTime.Parse(response.Headers["Last-Modified"]);

            string result = GetSchemaString(response, schemaLastModified);

            response.Close();

            // were done here. let others read.
            mre.Set();

            SchemaResult schemaResult = JsonConvert.DeserializeObject<SchemaResult>(result);
            return schemaResult.result ?? null;
        }
开发者ID:sy1989,项目名称:Dota2DroplistJson,代码行数:43,代码来源:Schemazh.cs

示例9: IsFirstInstance

    /// <summary>
    /// Creates the single instance.
    /// </summary>
    /// <param name="name">The name.</param>
    /// <returns></returns>
    public static bool IsFirstInstance(string name)
    {
      EventWaitHandle eventWaitHandle = null;
      string eventName = string.Format("{0}-{1}", Environment.MachineName, name);

      var isFirstInstance = false;

      try
      {
        // try opening existing wait handle
        eventWaitHandle = EventWaitHandle.OpenExisting(eventName);
      }
      catch
      {
        // got exception = handle wasn't created yet
        isFirstInstance = true;
      }

      if (isFirstInstance)
      {
        // init handle
        eventWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName);

        // register wait handle for this instance (process)
        ThreadPool.RegisterWaitForSingleObject(eventWaitHandle, WaitOrTimerCallback, null, Timeout.Infinite, false);
        eventWaitHandle.Close();
      }

      return isFirstInstance;
    }
开发者ID:cornelius90,项目名称:InnovatorAdmin,代码行数:35,代码来源:SingleInstance.cs

示例10: Start

        public void Start(EventWaitHandle startEventHandle)
        {
            Contract.Requires<ArgumentNullException>(startEventHandle != null, "startEventHandle");

            if (!Active)
            {
                var waitHandle = new ManualResetEventSlim(false);

                lock (_listener)
                {
                    _shuttingDown = false;

                    _listener.Start();

                    _acceptSocketThread = new Thread(AcceptSocketLoop);

                    _acceptSocketThread.Start(waitHandle);
                }

                waitHandle.Wait();

                _logger.DebugFormat("started on {0}", LocalEndPoint);
            }

            startEventHandle.Set();
        }
开发者ID:hanswolff,项目名称:FryProxy,代码行数:26,代码来源:HttpProxyWorker.cs

示例11: ResolveToString

        public override string ResolveToString()
        {
            if (!Parameters.Contains("url") || string.IsNullOrEmpty(Parameters["url"].ToString()))
                throw new InvalidOperationException();

            string url = Parameters["url"].ToString();

            string resultString = null;

            using (var wc = new WebClient())
            {
                var tlock = new EventWaitHandle(false, EventResetMode.ManualReset);
                wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler((sender, e) =>
                {
                    // TODO: Add progress monitoring
                });
                wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler((sender, e) =>
                {
                    resultString = e.Result;
                    tlock.Set();
                });
                wc.DownloadStringAsync(new Uri(url));
                tlock.WaitOne();
                tlock.Dispose();
            }

            return resultString;
        }
开发者ID:Craftitude-Team,项目名称:Craftitude-ClientApi,代码行数:28,代码来源:DownloadResolver.cs

示例12: Message

        /// <summary>
        /// Constructor for a message with or without waiting mechanism
        /// </summary>
        /// <param name="action"></param>
        /// <param name="waitForInvocation">When true, the message creator requires a waiting mechanism</param>
        public Message(Action action, bool waitForInvocation)
        {
            this.m_action = action;

            if (waitForInvocation) this.m_waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset);
            else this.m_waitHandle = null;
        }
开发者ID:wow4all,项目名称:evemu_server,代码行数:12,代码来源:Message.cs

示例13: CreateSingleInstance

        public static bool CreateSingleInstance(string name, EventHandler<InstanceCallbackEventArgs> callback, string[] args)
        {
            string eventName = string.Format("{0}-{1}", Environment.MachineName, name);

            InstanceProxy.IsFirstInstance = false;
            InstanceProxy.CommandLineArgs = args;

            try
            {
                using (EventWaitHandle eventWaitHandle = EventWaitHandle.OpenExisting(eventName))
                {
                    UpdateRemoteObject(name);

                    if (eventWaitHandle != null) eventWaitHandle.Set();
                }

                Environment.Exit(0);
            }
            catch
            {
                InstanceProxy.IsFirstInstance = true;

                using (EventWaitHandle eventWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName))
                {
                    ThreadPool.RegisterWaitForSingleObject(eventWaitHandle, WaitOrTimerCallback, callback, Timeout.Infinite, false);
                }

                RegisterRemoteType(name);
            }

            return InstanceProxy.IsFirstInstance;
        }
开发者ID:noscripter,项目名称:ShareX,代码行数:32,代码来源:ApplicationInstanceManager.cs

示例14: Installer

        public Installer(string filename)
        {
            try {
                MsiFilename = filename;
                Task.Factory.StartNew(() => {
                    // was coapp just installed by the bootstrapper?
                    if (((AppDomain.CurrentDomain.GetData("COAPP_INSTALLED") as string) ?? "false").IsTrue()) {
                        // we'd better make sure that the most recent version of the service is running.
                        EngineServiceManager.InstallAndStartService();
                    }
                    InstallTask = LoadPackageDetails();
                });

                bool wasCreated;
                var ewhSec = new EventWaitHandleSecurity();
                ewhSec.AddAccessRule(new EventWaitHandleAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), EventWaitHandleRights.FullControl, AccessControlType.Allow));
                _ping = new EventWaitHandle(false, EventResetMode.ManualReset, "BootstrapperPing", out wasCreated, ewhSec);

                // if we got this far, CoApp must be running.
                try {
                    Application.ResourceAssembly = Assembly.GetExecutingAssembly();
                } catch {
                }

                _window = new InstallerMainWindow(this);
                _window.ShowDialog();

                if (Application.Current != null) {
                    Application.Current.Shutdown(0);
                }
                ExitQuick();
            } catch (Exception e) {
                DoError(InstallerFailureState.FailedToGetPackageDetails, e);
            }
        }
开发者ID:ericschultz,项目名称:coapp,代码行数:35,代码来源:Installer.cs

示例15: SharedMemoryListener

 public SharedMemoryListener(IPCPeer peer)
 {
     _waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset, EventName);
     _exit = false;
     _peer = peer;
     _lastSyncedVersion = null;
 }
开发者ID:alongubkin,项目名称:watchog,代码行数:7,代码来源:SharedMemoryListener.cs


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