當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。