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


C# AutoResetEvent.Reset方法代码示例

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


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

示例1: Test_Add_and_Retrieve

        public void Test_Add_and_Retrieve()
        {
            var testBooking = CreateTestBooking();

            Booking actual = null;
            var waiter = new AutoResetEvent(false);
            _client.AddBookingAsync(testBooking, booking =>
                {
                    actual = booking;
                    waiter.Set();
                });

            Assert.IsTrue(waiter.WaitOne(1000), "Timeout waiting for WCF asynk result");
            Assert.AreNotSame(testBooking, actual, "WCF trip over the wire should have created a new object through serialisation");

            //Test that Get the saved booking works over WCF
            IEnumerable<Booking> actualBookings = null;
            waiter.Reset();
            _client.GetBookingsAsync(DateTime.Now, bookings =>
            {
                actualBookings = bookings;
                waiter.Set();
            });

            Assert.IsTrue(waiter.WaitOne(1000), "Timeout waiting for WCF asynk result");

            var retrievedBooking = actualBookings.FirstOrDefault();
            Assert.IsNotNull(retrievedBooking, "Bookings should contain created booking");
            Assert.AreEqual(testBooking.Id, retrievedBooking.Id, "Id is not persisted corectly");
            Assert.AreEqual(testBooking.ClientName, retrievedBooking.ClientName, "ClientName is not persisted corectly");
            Assert.AreEqual(testBooking.Duration, retrievedBooking.Duration, "Duration is not persisted corectly");
            Assert.AreEqual(testBooking.Slot, retrievedBooking.Slot, "Slot is not persisted corectly");
        }
开发者ID:stefanidi,项目名称:NineITBookingAppByRomanStefanidi,代码行数:33,代码来源:WcfTests.cs

示例2: CanCaptureAudio

        public void CanCaptureAudio()
        {
            int n = 0;
            SoundInTests((c) =>
            {
                for (int i = 0; i < 500; i++)
                {
                    var waitHandle = new AutoResetEvent(true);

                    c.DataAvailable += (s, e) =>
                    {
                        waitHandle.Reset();
                    };

                    c.Initialize();
                    c.Start();

                    if (!waitHandle.WaitOne(2000))
                        Assert.Fail("Timeout");
                    else
                    {
                        Debug.WriteLine(n.ToString());
                        n++;
                    }

                    c.Stop();

                    waitHandle.Dispose();
                }
            });
        }
开发者ID:CheViana,项目名称:AudioLab,代码行数:31,代码来源:SoundInBehaviourTests.cs

示例3: Main

        static void Main(string[] args)
        {
            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                // Add ChannelManager
                ChannelManagerService channelmgr = new ChannelManagerService();
                workflowRuntime.AddService(channelmgr);
                
                AutoResetEvent waitHandle = new AutoResetEvent(false);
                workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) { Console.WriteLine("WorkflowCompleted: " + e.WorkflowInstance.InstanceId.ToString()); waitHandle.Set(); };
                workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e) { Console.WriteLine("WorkflowTerminated: " + e.Exception.Message); waitHandle.Set(); };

                while (true)
                {
                    WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(Microsoft.WorkflowServices.Samples.SequentialCalculatorClient));
                    Console.WriteLine("Start SequentialCalculatorClient.");
                    instance.Start();
                    waitHandle.WaitOne();
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Do another calculation? (Y)");
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Press <enter> to exit.");
                    Console.ResetColor();
                    string input = Console.ReadLine();
                    if (input.Length == 0 || input[0] != 'Y')
                        break;
                    waitHandle.Reset();
                }
            }
        }
开发者ID:spzenk,项目名称:sfdocsamples,代码行数:30,代码来源:Program.cs

示例4: TestRefreshAmount

        public void TestRefreshAmount()
        {
            var mock = new MockRepository();
              var getAmountEventReceived = new AutoResetEvent(false);

              var accountServiceMock = mock.StrictMock<IAccountService>();
              var getAmountResetEventMock = mock.StrictMock<AutoResetEvent>();

              var expectedAccountId = new Random().Next(100);
              var accountInfoToTest = new AccountInfo(expectedAccountId, accountServiceMock, getAmountResetEventMock);

              var expectedReturnAmount = new Random().NextDouble();
              Expect.Call(getAmountResetEventMock.WaitOne(0)).Return(true);
              Expect.Call(getAmountResetEventMock.WaitOne(0)).Return(false);
              Expect.Call(accountServiceMock.GetAccountAmount(expectedAccountId)).Return(expectedReturnAmount);
              Expect.Call(getAmountResetEventMock.Set()).Return(true).WhenCalled(MethodInvocation => getAmountEventReceived.Set());
              mock.ReplayAll();

              getAmountEventReceived.Reset();

              accountInfoToTest.RefreshAmount();
              accountInfoToTest.RefreshAmount();

              Assert.IsTrue(getAmountEventReceived.WaitOne(1000));
              Assert.AreEqual(expectedReturnAmount, accountInfoToTest.Amount);

              mock.VerifyAll();
        }
开发者ID:justinmai,项目名称:DeveloperAssignment,代码行数:28,代码来源:TestMethod.cs

示例5: OpenRepositoryWithRetry

        public Repository OpenRepositoryWithRetry(IAbsoluteDirectoryPath path, bool createWhenNotExisting = false,
            Action failAction = null) {
            if (createWhenNotExisting && !path.Exists)
                return new Repository(path, createWhenNotExisting);

            using (var autoResetEvent = new AutoResetEvent(false))
            using (var fileSystemWatcher =
                new FileSystemWatcher(path.ToString(), "*.lock") {
                    EnableRaisingEvents = true
                }) {
                var lockFile = path.GetChildFileWithName(Repository.LockFile);
                var fp = Path.GetFullPath(lockFile.ToString());
                fileSystemWatcher.Deleted +=
                    (o, e) => {
                        if (Path.GetFullPath(e.FullPath) == fp)
                            autoResetEvent.Set();
                    };

                while (true) {
                    using (var timer = UnlockTimer(lockFile, autoResetEvent)) {
                        try {
                            return new Repository(path, createWhenNotExisting);
                        } catch (RepositoryLockException) {
                            if (failAction != null)
                                failAction();
                            timer.Start();
                            autoResetEvent.WaitOne();
                            lock (timer)
                                timer.Stop();
                            autoResetEvent.Reset();
                        }
                    }
                }
            }
        }
开发者ID:MaHuJa,项目名称:withSIX.Desktop,代码行数:35,代码来源:RepositoryFactory.cs

示例6: TestDelete

 public void TestDelete()
 {
     FileInfo file = new FileInfo(@"d:\X16-42552VS2010UltimTrial1.txt");
     AutoResetEvent are = new AutoResetEvent(false);
     string key = null;
     HttpCommunicate.Upload(file, (result, warning) =>
     {
         Console.WriteLine("result:" + result);
         key = result + "";
         are.Set();
     }, error =>
     {
         Console.WriteLine("error:" + error);
         are.Set();
     });
     are.WaitOne();
     are.Reset();
     FileDeletePackage package = new FileDeletePackage();
     package.key = key;
     HttpCommunicate.Request(package, (result, warning) =>
     {
         Console.WriteLine("file:" + result);
         are.Set();
     }, error =>
     {
         Console.WriteLine("error:" + error);
         are.Set();
     });
     are.WaitOne();
 }
开发者ID:wangjianglin,项目名称:dotnet-core,代码行数:30,代码来源:FileTest.cs

示例7: PlaybackSurface

		public PlaybackSurface()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();
			AREObj = new System.Threading.AutoResetEvent(false);
			AREObj.Reset();
			m_PlaybackControlList = new PlaybackControlList();
			m_bControlsVisible = true;
			txtTime.Text = "000000";
		}
开发者ID:CarverLab,项目名称:Oyster,代码行数:10,代码来源:PlaybackSurface.cs

示例8: WebDAVInterface

        /// <summary>
        /// 
        /// </summary>
        /// <param name="server">path to the server, like "http://privatenotes.dyndns-server.com"</param>
        /// <param name="path">path, starting fromt he server root-url, like "/webdav2/username/"</param>
        /// <param name="user">username for login</param>
        /// <param name="pass">pw for login</param>
        /// <param name="checkSSlCertificates">if true, an ssl certificate (if https is used) will be checked,
        /// if false, the ssl check will be ommited (has to be used for self-signed certificates etc)</param>
        public WebDAVInterface(String server, String path, String user, String pass, bool checkSSlCertificates)
        {
            //Logger.Debug("creating server " + server + " path " + path + " user " + user + " pass " + pass);
            client = new WebDAVClient();
            client.Server = server;
            client.BasePath = path;
            client.User = user;
            client.Pass = pass;
            client.SSLCertVerification = checkSSlCertificates;
            autoReset = new AutoResetEvent(false);
            autoReset.Reset();

            client.ListComplete += list;
            client.DownloadComplete += download;
            client.UploadComplete += upload;
            client.DeleteComplete += delete;
        }
开发者ID:NoUsername,项目名称:PrivateNotes,代码行数:26,代码来源:WebDAVInterface.cs

示例9: ShouldAutomaticallyReleaseDataWhenThreadIsReturnedToThePool

        public virtual void ShouldAutomaticallyReleaseDataWhenThreadIsReturnedToThePool()
        {
            try
            {
                ThreadPool.SetMinThreads(1, 1);
                ThreadPool.SetMaxThreads(1, 1);
                var mainEvent = new AutoResetEvent(false);
                int? threadId = null;
                int? otherThreadId = null;
                object data = null;
                ThreadPool.QueueUserWorkItem(
                    delegate(object ev)
                    {
                        LogicContext.SetData("Test4", 100);
                        threadId = Thread.CurrentThread.ManagedThreadId;
                        ((AutoResetEvent)ev).Set();
                    }, 
                    mainEvent);

                mainEvent.WaitOne();

                mainEvent.Reset();

                Assert.IsNotNull(threadId);

                ThreadPool.QueueUserWorkItem(
                    delegate(object ev)
                    {
                        otherThreadId = Thread.CurrentThread.ManagedThreadId;
                        data = LogicContext.FindData("Test4");
                        ((AutoResetEvent)ev).Set();
                    }, 
                    mainEvent);
                mainEvent.WaitOne();

                Assert.IsNotNull(otherThreadId);
                Assert.AreEqual(threadId.Value, otherThreadId.Value);
                Assert.IsNull(data);
            }
            finally
            {
                ThreadPool.SetMinThreads(2, 2);
                ThreadPool.SetMaxThreads(1023, 1000);
            }
        }
开发者ID:NikGovorov,项目名称:Taijutsu,代码行数:45,代码来源:LogicContextFixture.cs

示例10: findBestMoveWithTimeout

        public lineAndScore findBestMoveWithTimeout(baseBoard boardToMove, int timeout)
        {
            findBestMoveBoard = boardToMove;
            Thread findThread = new Thread(findBestMoveWithTimeoutThread);
            evnt = new AutoResetEvent(false);
            evnt.Reset();
            findThread.Start();
            if (evnt.WaitOne(timeout, false))
            {
                if (ex != null)
                    throw ex;
                return bestLine;
            }

            findThread.Abort();

            throw new Exception("Player timeout");
        }
开发者ID:randomdude,项目名称:DoktorChess,代码行数:18,代码来源:moveWithTimeout.cs

示例11: NLoopConsumeTest

        static void NLoopConsumeTest()
        {
            AutoResetEvent autoResetEvent = new AutoResetEvent(false); //声明 false, WaitOne时线程等待
            while (true)
            {
                autoResetEvent.Reset(); //WaitOne时,使线程等待
                //todo:从队列取数据

                //消费者
                Task.Run(() =>
                {
                    //todo:处理数据
                    autoResetEvent.Set(); //消费完成,允许线程继续
                });
                autoResetEvent.WaitOne(); //等待某个消费者空闲,线程等待

            }
        }
开发者ID:supernebula,项目名称:Plunder,代码行数:18,代码来源:EventWaitHandleTest.cs

示例12: ExecuteMethodWithTimeout

        /// <summary>
        /// fire and forget
        /// </summary>
        /// <param name="millisecondsTimeout"></param>
        /// <param name="method"></param>
        public static void ExecuteMethodWithTimeout(int millisecondsTimeout, Action method)
        {
            AutoResetEvent timeoutEvent = new AutoResetEvent(false);
            Thread methodInvoker = new Thread(delegate()
            {
                method();
                timeoutEvent.Set();
            });

            timeoutEvent.Reset();
            methodInvoker.Start();

            if (timeoutEvent.WaitOne(millisecondsTimeout, false) == false)
            {
                methodInvoker.Abort();
                throw new TimeoutException();
            }
        }
开发者ID:powermedia,项目名称:PowerMedia.Common,代码行数:23,代码来源:ThreadUtils.cs

示例13: CopyFolder

 public void CopyFolder(InventoryFolder dest, InventoryFolder folder)
 {
     UUID newFolderID = Client.Inventory.CreateFolder(dest.UUID, folder.Name, AssetType.Unknown);
     Thread.Sleep(500);
     var items = Client.Inventory.FolderContents(folder.UUID, folder.OwnerID, true, true, InventorySortOrder.ByDate, 45 * 1000);
     AutoResetEvent copied = new AutoResetEvent(false);
     foreach (var item in items)
     {
         if (item is InventoryItem)
         {
             copied.Reset();
             Client.Inventory.RequestCopyItem(item.UUID, newFolderID, item.Name, folder.OwnerID, (InventoryBase target) =>
             {
                 Instance.TabConsole.DisplayNotificationInChat(string.Format("    * Copied {0} to {1}", item.Name, dest.Name));
                 copied.Set();
             });
             copied.WaitOne(15 * 1000, false);
         }
     }
 }
开发者ID:TooheyPaneer,项目名称:radegast,代码行数:20,代码来源:FolderCopy.cs

示例14: Main

        static void Main(string[] args)
        {
            EventWaitHandle waitHandle = new AutoResetEvent(false);

            Worker worker1 = new Worker("Worker1", waitHandle);
            Worker worker2 = new Worker("Worker2", waitHandle);

            Console.WriteLine("press 'g' to start threads");
            Console.WriteLine("Press 'p' to pause threads");
            Console.WriteLine("Press 'q' to quit");

            Thread.Sleep(2000);

            worker1.Start();
            worker2.Start();

            while (true) {
                ConsoleKey key = Console.ReadKey(true).Key;
                switch (key) {
                    case ConsoleKey.G:
                        Console.WriteLine("starting...");
                        waitHandle.Set();
                        break;
                    case ConsoleKey.P:
                        Console.WriteLine("pausing...");
                        waitHandle.Reset();
                        break;
                    case ConsoleKey.Q:
                        Console.WriteLine("quitting...");
                        worker1.Stop();
                        worker2.Stop();
                        return;
                    default:
                        break;
                }
            }
        }
开发者ID:serakrin,项目名称:presentations,代码行数:37,代码来源:Program.cs

示例15: ExecuteMethodWithTimeoutSync

        /// <summary>
        /// wait for end of execution or timeout
        /// </summary>
        /// <param name="millisecondsTimeout"></param>
        /// <param name="method"></param>
        /// <returns>true if method executed in less than timeout</returns>
        public static bool ExecuteMethodWithTimeoutSync(int millisecondsTimeout, Action method)
        {
            AutoResetEvent timeoutEvent = new AutoResetEvent(false);
            var executed = false;
            Thread methodInvoker = new Thread(delegate()
            {
                method();
                timeoutEvent.Set();
                executed = true;
            });

            timeoutEvent.Reset();
            methodInvoker.Start();

            if (timeoutEvent.WaitOne(millisecondsTimeout, false) == false)
            {
                methodInvoker.Abort();
            }
            else
            {
                methodInvoker.Join();
            }
            return executed;
        }
开发者ID:powermedia,项目名称:PowerMedia.Common,代码行数:30,代码来源:ThreadUtils.cs


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