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


C# EventWaitHandle.Set方法代码示例

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


在下文中一共展示了EventWaitHandle.Set方法的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: StartMission

        public void StartMission(string missionName)
        {
            var down = Program.Downloader.GetResource(DownloadType.MISSION, missionName);
            if (down == null)
            {
                //okay Mission exist, but lets check for dependency!
                down = Program.Downloader.GetDependenciesOnly(missionName);
            }

            var engine = Program.Downloader.GetResource(DownloadType.ENGINE, Program.TasClient.ServerWelcome.Engine ?? GlobalConst.DefaultEngineOverride);

            var metaWait = new EventWaitHandle(false, EventResetMode.ManualReset);
            Mod modInfo = null;
            Program.MetaData.GetModAsync(missionName,
                mod =>
                {
                    if (!mod.IsMission)
                    {
                        Program.MainWindow.InvokeFunc(() => { WarningBar.DisplayWarning(string.Format("{0} is not a valid mission", missionName)); });
                    }

                    else modInfo = mod;

                    metaWait.Set();
                },
                error =>
                {
                    Program.MainWindow.InvokeFunc(() =>
                    {
                        WarningBar.DisplayWarning(string.Format("Download of metadata failed: {0}", error.Message));
                        //container.btnStop.Enabled = true;
                    });
                    metaWait.Set();
                });

            var downloads = new List<Download>() { down, engine }.Where(x => x != null).ToList();
            if (downloads.Count > 0)
            {
                var dd = new WaitDownloadDialog(downloads);
                if (dd.ShowDialog(Program.MainWindow) == DialogResult.Cancel)
                {
                    Program.MainWindow.InvokeFunc(() => Program.NotifySection.RemoveBar(this));
                    return;
                }
            }
            metaWait.WaitOne();

            var spring = new Spring(Program.SpringPaths);
            spring.RunLocalScriptGame(modInfo.MissionScript, Program.TasClient.ServerWelcome.Engine ?? GlobalConst.DefaultEngineOverride);
            var cs = GlobalConst.GetContentService();
            cs.NotifyMissionRun(Program.Conf.LobbyPlayerName, missionName);
            spring.SpringExited += (o, args) => RecordMissionResult(spring, modInfo);
            Program.MainWindow.InvokeFunc(() => Program.NotifySection.RemoveBar(this));
        }
开发者ID:GoogleFrog,项目名称:Zero-K-Infrastructure,代码行数:54,代码来源:MissionStarter.cs

示例3: Main

        static void Main(string[] args)
        {
            // Create a IPC wait handle with a unique identifier.
            bool createdNew;
            var waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, "ImperatorWaitHandle", out createdNew);

            // If the handle was already there, inform the other process to exit itself.
            // Afterwards we'll also die.
            if (!createdNew)
            {
                Console.WriteLine("Found other Imperator process. Requesting stop...");
                waitHandle.Set();
                Console.WriteLine("Informer exited.");

                return;
            }

            Console.WriteLine("Initializing Container...");
            var container = new ContainerInitializer().Initialize();

            Console.WriteLine("Connecting to UI...");
            var hubClient = container.GetInstance<IHubClient>();
            hubClient.OpenConnection();
            Console.WriteLine("Connected");

            Console.WriteLine("Initializing Imperator...");
            var i = container.GetInstance<Imperator>();
            i.InitializeConfig();
            i.StartImperator();

            waitHandle.WaitOne();
            Console.WriteLine("Closing Imperator...");
        }
开发者ID:docrinehart,项目名称:deathstar-imperator,代码行数:33,代码来源:Program.cs

示例4: DoubleLaunchLocker

 public DoubleLaunchLocker(string signalId, string waitId, bool force = false)
 {
     _force = force;
     SignalId = signalId;
     WaitId = waitId;
     bool isNew;
     _signalHandler = new EventWaitHandle(false, EventResetMode.AutoReset, signalId, out isNew);
     if (!isNew)
     {
         Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
         bool terminate = false;
         if (!force && !RequestConfirmation())
             terminate = true;
         if (!terminate)
         {
             _waitHandler = new EventWaitHandle(false, EventResetMode.AutoReset, waitId);
             if (_signalHandler.Set())
                 terminate = !_waitHandler.WaitOne(TIMEOUT);
             else
                 terminate = true;
         }
         if (terminate)
         {
             TryShutdown();
             ForceShutdown();
         }
         else
             Application.Current.ShutdownMode = ShutdownMode.OnLastWindowClose;
     }
     ThreadPool.QueueUserWorkItem(WaitingHandler, waitId);
 }
开发者ID:hjlfmy,项目名称:Rubezh,代码行数:31,代码来源:SingleLaunchHelper.cs

示例5: Controller

 public Controller(BlockingMediator mediator)
 {
     _signal = new AutoResetEvent(false);
     mediator.AddSignal(_signal);
     dynamic config = ConfigurationManager.GetSection("delays");
     var delays = new Dictionary<MessageType, int>();
     foreach (string name in config)
     {
         delays[Hearts.Utility.Enum.Parse<MessageType>(name)] =
             int.Parse(config[name]);
     }
     foreach (var type in Hearts.Utility.Enum.GetValues<MessageType>())
     {
         var key = type;
         mediator.Subscribe(type, ignore =>
             {
                 if (delays.ContainsKey(key))
                 {
                     Thread.Sleep(delays[key]);
                 }
                 _signal.Reset();
                 if (!IsBlocking)
                 {
                     ThreadPool.QueueUserWorkItem(_ => _signal.Set());
                 }
             });
     }
 }
开发者ID:sdevlin,项目名称:clarity-hearts,代码行数:28,代码来源:Controller.cs

示例6: Should_be_able_to_cancel_message_reception_with_a_cancellation_token

        public void Should_be_able_to_cancel_message_reception_with_a_cancellation_token()
        {
            const string mmfName = "Local\\test";
            var message = "not null";
            var messageCancelled = new EventWaitHandle(false, EventResetMode.ManualReset, mmfName + "_MessageCancelled");

            messageCancelled.Set();

            using (var messageReceiver = new MemoryMappedFileMessageReceiver(mmfName))
            using (var cancellationTokenSource = new CancellationTokenSource())
            {
                var task = new Task(() => message = messageReceiver.ReceiveMessage(ReadString, cancellationTokenSource.Token));

                task.Start();

                var isSet = true;

                while (isSet)
                    isSet = messageCancelled.WaitOne(0);

                cancellationTokenSource.Cancel();

                task.Wait();

                message.ShouldBeNull();
            }
        }
开发者ID:kushniro,项目名称:MemoryMessagePipe,代码行数:27,代码来源:Tests.cs

示例7: AbsoluteTimerWaitHandle

        public AbsoluteTimerWaitHandle(DateTimeOffset dueTime)
        {
            _dueTime = dueTime;
            _eventWaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);

            SafeWaitHandle = _eventWaitHandle.SafeWaitHandle;

            var dueSpan = (_dueTime - DateTimeOffset.Now);
            var period = new TimeSpan(dueSpan.Ticks / 10);

            if (dueSpan < TimeSpan.Zero)
            {
                _eventWaitHandle.Set();
            }
            else
            {
                _timer = new Timer(period.TotalMilliseconds)
                {
                    AutoReset = false,
                };

                _timer.Elapsed += TimerOnElapsed;

                _timer.Start();
            }
        }
开发者ID:hash,项目名称:trigger.net,代码行数:26,代码来源:PlatformIndependentNative.cs

示例8: Waiter

 public Waiter(TimeSpan? interval = null)
 {
     _waitHandle = new AutoResetEvent(false);
     _timer = new System.Timers.Timer();
     _timer.Elapsed += (sender, args) => _waitHandle.Set();
     SetInterval(interval);
 }
开发者ID:jeldis,项目名称:CSharp,代码行数:7,代码来源:Waiter.cs

示例9: OnlyOneCopy

        private static bool OnlyOneCopy()
        {
            bool isnew;
            s_setup_mutex = new Mutex(true, SETUP_MUTEX_NAME, out isnew);

            RestoreEvent = null;
            try
            {
#if RELEASE
                RestoreEvent = AutoResetEvent.OpenExisting(EVENT_NAME);
                RestoreEvent.Set();
                return false;
            }
            catch (WaitHandleCannotBeOpenedException)
            {
#endif
                string user = Environment.UserDomainName + "\\" + Environment.UserName;
                EventWaitHandleSecurity evh_sec = new EventWaitHandleSecurity();

                EventWaitHandleAccessRule rule = new EventWaitHandleAccessRule(user,
                    EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify,
                    AccessControlType.Allow);
                evh_sec.AddAccessRule(rule);

                bool was_created;
                RestoreEvent = new EventWaitHandle(false, EventResetMode.AutoReset, 
                    EVENT_NAME, out was_created, evh_sec);
            }
            catch (Exception)
            {
            }

            return true;
        }
开发者ID:KebinuChiousu,项目名称:MangaCrawler,代码行数:34,代码来源:Program.cs

示例10: 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

示例11: Should_be_able_to_cancel_message_reception_upon_disposal

        public void Should_be_able_to_cancel_message_reception_upon_disposal()
        {
            const string mmfName = "Local\\test";
            var message = "not null";
            var messageCancelled = new EventWaitHandle(false, EventResetMode.ManualReset, mmfName + "_MessageCancelled");

            messageCancelled.Set();

            var messageReceiver = new MemoryMappedFileMessageReceiver(mmfName);

            var task = new Task(() => message = messageReceiver.ReceiveMessage(ReadString));

            task.Start();

            var isSet = true;

            while (isSet)
                isSet = messageCancelled.WaitOne(0);

            messageReceiver.Dispose();

            task.Wait();

            message.ShouldBeNull();
        }
开发者ID:kushniro,项目名称:MemoryMessagePipe,代码行数:25,代码来源:Tests.cs

示例12: 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

示例13: ServerResponds

 public void ServerResponds() {
   using (var container = SetupMefContainer()) {
     using (var server = container.GetExport<IServerProcessProxy>().Value) {
       var waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
       var request = new IpcRequest {
         RequestId = 5,
         Protocol = IpcProtocols.Echo,
         Data = new IpcStringData {
           Text = "sdfsdsd"
         }
       };
       IpcResponse response = null;
       server.RunAsync(request, x => {
         response = x;
         waitHandle.Set();
       });
       Assert.IsTrue(waitHandle.WaitOne(TimeSpan.FromSeconds(5.0)), "Server did not respond within 5 seconds.");
       Assert.AreEqual(5, response.RequestId);
       Assert.AreEqual(IpcProtocols.Echo, response.Protocol);
       Assert.IsNotNull(request.Data);
       Assert.IsNotNull(response.Data);
       Assert.AreEqual(request.Data.GetType(), typeof(IpcStringData));
       Assert.AreEqual(response.Data.GetType(), typeof(IpcStringData));
       Assert.AreEqual((request.Data as IpcStringData).Text, (response.Data as IpcStringData).Text);
     }
   }
 }
开发者ID:mbbill,项目名称:vs-chromium,代码行数:27,代码来源:TestEchoProtocol.cs

示例14: AuthSignIn

        void AuthSignIn()
        {
            EventWaitHandle wait = new EventWaitHandle(false, EventResetMode.ManualReset);
            SlackSocketClient client = new SlackSocketClient(token);
            client.OnHello += () =>
            {
                wait.Set();
            };
            client.Connect((l) =>
            {

                if (!l.ok) return;

                BeginInvoke(new Action(() =>
                {
                    connected = new ConnectedInterface(client, l);
                    connected.Dock = DockStyle.Fill;

                    Controls.Add(connected);

                    password.Visible = false;
                }));
            });
            wait.WaitOne();
        }
开发者ID:seanfuture,项目名称:Slack,代码行数:25,代码来源:PrimaryInterface.cs

示例15: RunInThreadPoolWithEvents

        static void RunInThreadPoolWithEvents()
        {
            double result = 0d;

            // We use this event to signal when the thread is don executing.
            EventWaitHandle calculationDone = new EventWaitHandle(false, EventResetMode.AutoReset);

            // Create a work item to read from I/O
            ThreadPool.QueueUserWorkItem((x) => {
                result += Utils.CommonFunctions.ReadDataFromIO();
                calculationDone.Set();
            });

            // Save the result of the calculation into another variable
            double result2 = Utils.CommonFunctions.DoIntensiveCalculations();

            // Wait for the thread to finish
            calculationDone.WaitOne();

            // Calculate the end result
            result += result2;

            // Print the result
            Console.WriteLine("The result is {0}", result);
        }
开发者ID:vikramadhav,项目名称:Certification_70-483,代码行数:25,代码来源:Program.cs


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