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


C# AutoResetEvent.Set方法代码示例

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


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

示例1: SetReset

 public void SetReset()
 {
     using (AutoResetEvent are = new AutoResetEvent(false))
     {
         Assert.False(are.WaitOne(0));
         are.Set();
         Assert.True(are.WaitOne(0));
         Assert.False(are.WaitOne(0));
         are.Set();
         are.Reset();
         Assert.False(are.WaitOne(0));
     }
 }
开发者ID:ESgarbi,项目名称:corefx,代码行数:13,代码来源:AutoResetEventTests.cs

示例2: PosTest1

    public bool PosTest1()
    {
        bool           retVal = true;
        AutoResetEvent are;

        TestLibrary.TestFramework.BeginScenario("PosTest1: AutoResetEvent.Set()");

        try
        {
            // false means that the initial state should be not signaled
            are = new AutoResetEvent(false);

            // set the signal
            if (!are.Set())
            {
                TestLibrary.TestFramework.LogError("001", "AutoResetEvent.Set() failed");
                retVal = false;
            }

            // verify that the autoreset event is signaled
            // if it is not signaled the following call will block for ever
            TestLibrary.TestFramework.LogInformation("Calling AutoResetEvent.WaitOne()... if the event is not signaled it will hang");
            are.WaitOne();

        }
        catch (Exception e)
        {
            TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
            retVal = false;
        }

        return retVal;
    }
开发者ID:l1183479157,项目名称:coreclr,代码行数:33,代码来源:autoreseteventset.cs

示例3: HandleCharacter

    private static void HandleCharacter(Match match, HttpListenerResponse response)
    {
        // here we are running in a thread different from the main thread
        int pid = Convert.ToInt32(match.Groups[1].Value);

        string responseString = "";

        // event used to wait the answer from the main thread.
        AutoResetEvent autoEvent = new AutoResetEvent(false);

        // var to store the character we are looking for
        Character character = null;
        // this bool is to check character is valid ... explanation below
        bool found = false;

        // we queue an 'action' to be executed in the main thread
        MainGameObject.QueueOnMainThread(()=>{
            // here we are in the main thread (see Update() in MainGameObject.cs)
            // retrieve the character
            character = MainGameObject.Instance().CharacterByID(pid);
            // if the character is null set found to false
            // have to do this because cannot call "character==null" elsewhere than the main thread
            // do not know why (yet?)
            // so if found this "trick"
            found = (character!=null?true:false);
            // set the event to "unlock" the thread
            autoEvent.Set();
        });

        // wait for the end of the 'action' executed in the main thread
        autoEvent.WaitOne();

        // generate the HTTP answer

        if (found==false) {
            responseString = "<html><body>character: not found (" + pid + ")</body></html>";
        } else {
            responseString = "<html><body>";
            responseString += "<img src='data:image/jpg;base64," + character.imageB64 + "'></img></br>";
            responseString += "name: " +  character.name + "</br>";
            responseString += "life: " +  character.life + "</br>";
            responseString += "streght " +  character.streght + "</br>";
            responseString += "dexterity " +  character.dexterity + "</br>";
            responseString += "consitution " +  character.consitution + "</br>";
            responseString += "intelligence " +  character.intelligence + "</br>";
            responseString += "</body></html>";
        }

        byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
        // Get a response stream and write the response to it.
        response.ContentLength64 = buffer.Length;
        System.IO.Stream output = response.OutputStream;
        output.Write(buffer,0,buffer.Length);
        // You must close the output stream.
        output.Close();
    }
开发者ID:rxra,项目名称:UnityHTTPListener,代码行数:56,代码来源:HTTPServer.cs

示例4: Go

    public void Go()
    {
        // find all the upcoming UK horse races (EventTypeId 7)
        var marketFilter = new MarketFilter();
        marketFilter.EventTypeIds = new HashSet<string>() { "7" };
        marketFilter.MarketStartTime = new TimeRange()
        {
            From = DateTime.Now,
            To = DateTime.Now.AddDays(2)
        };
        marketFilter.MarketTypeCodes = new HashSet<String>() { "WIN" };

        Console.WriteLine("BetfairClient.ListEvents()");
        var events = _client.ListEvents(marketFilter).Result;
        if (events.HasError)
            throw new ApplicationException();
        var firstEvent = events.Response.First();
        Console.WriteLine("First Event {0} {1}", firstEvent.Event.Id, firstEvent.Event.Name);

        var marketCatalogues = _client.ListMarketCatalogue(
          BFHelpers.HorseRaceFilter(),
          BFHelpers.HorseRaceProjection(),
          MarketSort.FIRST_TO_START,
          25).Result.Response;

        marketCatalogues.ForEach(c =>
        {
            _markets.Enqueue(c);
            Console.WriteLine(c.MarketName);
        });
        Console.WriteLine();

        while (_markets.Count > 0)
        {
            AutoResetEvent waitHandle = new AutoResetEvent(false);
            MarketCatalogue marketCatalogue;
            _markets.TryDequeue(out marketCatalogue);

            var marketSubscription = _streamingClient.SubscribeMarket(marketCatalogue.MarketId)
                .SubscribeOn(Scheduler.Default)
                .Subscribe(
                tick =>
                {
                    Console.WriteLine(BFHelpers.MarketSnapConsole(tick, marketCatalogue.Runners));
                },
                () =>
                {
                    Console.WriteLine("Market finished");
                    waitHandle.Set();
                });

            waitHandle.WaitOne();
            marketSubscription.Dispose();
        }
    }
开发者ID:csutcliff,项目名称:betfairng,代码行数:55,代码来源:StreamingExample.cs

示例5: WatchForEvents

    public static AutoResetEvent WatchForEvents(FileSystemWatcher watcher, WatcherChangeTypes actions)
    {
        AutoResetEvent eventOccurred = new AutoResetEvent(false);

        if (0 != (actions & WatcherChangeTypes.Changed))
        {
            watcher.Changed += (o, e) =>
            {
                Assert.Equal(WatcherChangeTypes.Changed, e.ChangeType);
                eventOccurred.Set();
            };
        }

        if (0 != (actions & WatcherChangeTypes.Created))
        {
            watcher.Created += (o, e) =>
            {
                Assert.Equal(WatcherChangeTypes.Created, e.ChangeType);
                eventOccurred.Set();
            };
        }

        if (0 != (actions & WatcherChangeTypes.Deleted))
        {
            watcher.Deleted += (o, e) =>
            {
                Assert.Equal(WatcherChangeTypes.Deleted, e.ChangeType);
                eventOccurred.Set();
            };
        }

        if (0 != (actions & WatcherChangeTypes.Renamed))
        {
            watcher.Renamed += (o, e) =>
            {
                Assert.Equal(WatcherChangeTypes.Renamed, e.ChangeType);
                eventOccurred.Set();
            };
        }

        return eventOccurred;
    }
开发者ID:noahfalk,项目名称:corefx,代码行数:42,代码来源:Utility.cs

示例6: Running_Timer_CanBeFinalizedAndStopsFiring

 public void Running_Timer_CanBeFinalizedAndStopsFiring()
 {
     AutoResetEvent are = new AutoResetEvent(false);
     TimerCallback tc = new TimerCallback((object o) => are.Set());
     var t = new Timer(tc, null, 1, 500);
     Assert.True(are.WaitOne(MaxPositiveTimeoutInMs), "Failed to get first timer fire");
     t = null; // Remove our refence so the timer can be GC'd
     GC.Collect();
     GC.WaitForPendingFinalizers();
     GC.Collect();
     Assert.False(are.WaitOne(500), "Should not have received a timer fire after it was collected");
 }
开发者ID:dotnet,项目名称:corefx,代码行数:12,代码来源:TimerFiringTests.cs

示例7: Timer_Fires_After_DueTime_Ellapses

    public void Timer_Fires_After_DueTime_Ellapses()
    {
        AutoResetEvent are = new AutoResetEvent(false);

        using (var t = new Timer(new TimerCallback((object s) =>
        {
            are.Set();
        }), null, TimeSpan.FromMilliseconds(250), TimeSpan.FromMilliseconds(Timeout.Infinite) /* not relevant */))
        {
            Assert.True(are.WaitOne(TimeSpan.FromMilliseconds(MaxPositiveTimeoutInMs)));
        }
    }
开发者ID:jmhardison,项目名称:corefx,代码行数:12,代码来源:TimerFiringTests.cs

示例8: NonRepeatingTimer_ThatHasAlreadyFired_CanChangeAndFireAgain

 public void NonRepeatingTimer_ThatHasAlreadyFired_CanChangeAndFireAgain()
 {
     AutoResetEvent are = new AutoResetEvent(false);
     TimerCallback tc = new TimerCallback((object o) => are.Set());
     using (var t = new Timer(tc, null, 1, Timeout.Infinite))
     {
         Assert.True(are.WaitOne(MaxPositiveTimeoutInMs), "Should have received first timer event");
         Assert.False(are.WaitOne(500), "Should not have received a second timer event");
         t.Change(10, Timeout.Infinite);
         Assert.True(are.WaitOne(MaxPositiveTimeoutInMs), "Should have received a second timer event after changing it");
     }
 }
开发者ID:dotnet,项目名称:corefx,代码行数:12,代码来源:TimerFiringTests.cs

示例9: Timer_Fires_AndPassesNullStateThroughCallback

    public void Timer_Fires_AndPassesNullStateThroughCallback()
    {
        AutoResetEvent are = new AutoResetEvent(false);

        using (var t = new Timer(new TimerCallback((object s) =>
        {
            Assert.Null(s);
            are.Set();
        }), null, TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(Timeout.Infinite) /* not relevant */))
        {
            Assert.True(are.WaitOne(TimeSpan.FromMilliseconds(MaxPositiveTimeoutInMs)));
        }
    }
开发者ID:jmhardison,项目名称:corefx,代码行数:13,代码来源:TimerFiringTests.cs

示例10: Timer_Change_BeforeDueTime_ChangesWhenTimerWillFire

    public void Timer_Change_BeforeDueTime_ChangesWhenTimerWillFire()
    {
        AutoResetEvent are = new AutoResetEvent(false);

        using (var t = new Timer(new TimerCallback((object s) =>
        {
            are.Set();
        }), null, TimeSpan.FromSeconds(500), TimeSpan.FromMilliseconds(50)))
        {
            Assert.False(are.WaitOne(TimeSpan.FromMilliseconds(100)), "The reset event should not have been set yet");
            t.Change(TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(-1));
            Assert.True(are.WaitOne(TimeSpan.FromMilliseconds(TimerFiringTests.MaxPositiveTimeoutInMs)), "Should have received a timer event after this new duration");
        }
    }
开发者ID:dotnet,项目名称:corefx,代码行数:14,代码来源:TimerChangeTests.cs

示例11: Run

	public int Run()
	{
		Stopwatch sw = new Stopwatch();		
		AutoResetEvent are = new AutoResetEvent(false);
		sw.Start();
		bool ret = are.WaitOne(1000);//,false);
		sw.Stop();
		//We should never get signaled
		if(ret)
		{
			Console.WriteLine("AutoResetEvent should never be signalled.");
			return -1;
		}

		if(sw.ElapsedMilliseconds < 900)
		{
			Console.WriteLine("It should take at least 900 milliseconds to call bool ret = are.WaitOne(1000,false);.");
			Console.WriteLine("sw.ElapsedMilliseconds = " + sw.ElapsedMilliseconds);			
			return -2;
		}
		
		are.Set();
		if(!are.WaitOne(0))//,false))
		{
			Console.WriteLine("Signalled event should always return true on call to !are.WaitOne(0,false).");
			return -3;
		}
		
		sw.Reset();		
		sw.Start();
		ret = are.WaitOne(1000);//,false);
		sw.Stop();
		//We should never get signaled
		if(ret)
		{
			Console.WriteLine("AutoResetEvent should never be signalled after is is AutoReset.");
			return -4;
		}

		if(sw.ElapsedMilliseconds < 900)
		{
			Console.WriteLine("It should take at least 900 milliseconds to call bool ret = are.WaitOne(1000,false);.");
			Console.WriteLine("sw.ElapsedMilliseconds = " + sw.ElapsedMilliseconds);			
			return -5;
		}
		
		return 100;
		
	}
开发者ID:CheneyWu,项目名称:coreclr,代码行数:49,代码来源:ConstructFalse.cs

示例12: Timer_FiresOnlyOnce_OnDueTime_With_InfinitePeriod

    public void Timer_FiresOnlyOnce_OnDueTime_With_InfinitePeriod()
    {
        int count = 0;
        AutoResetEvent are = new AutoResetEvent(false);

        using (var t = new Timer(new TimerCallback((object s) =>
        {
            if (Interlocked.Increment(ref count) >= 2)
            {
                are.Set();
            }
        }), null, TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(Timeout.Infinite) /* not relevant */))
        {
            Assert.False(are.WaitOne(TimeSpan.FromMilliseconds(250 /*enough for 2 fires + buffer*/)));
        }
    }
开发者ID:jmhardison,项目名称:corefx,代码行数:16,代码来源:TimerFiringTests.cs

示例13: Timer_Fires_After_DueTime_AndOn_Period

    public void Timer_Fires_After_DueTime_AndOn_Period()
    {
        int count = 0;
        AutoResetEvent are = new AutoResetEvent(false);

        using (var t = new Timer(new TimerCallback((object s) =>
        {
            if (Interlocked.Increment(ref count) >= 2)
            {
                are.Set();
            }
        }), null, TimeSpan.FromMilliseconds(250), TimeSpan.FromMilliseconds(50)))
        {
            Assert.True(are.WaitOne(TimeSpan.FromMilliseconds(MaxPositiveTimeoutInMs)));
        }
    }
开发者ID:jmhardison,项目名称:corefx,代码行数:16,代码来源:TimerFiringTests.cs

示例14: Timer_FiresOnlyOnce_OnDueTime_With_InfinitePeriod

    public void Timer_FiresOnlyOnce_OnDueTime_With_InfinitePeriod()
    {
        int count = 0;
        AutoResetEvent are = new AutoResetEvent(false);

        using (var t = new Timer(new TimerCallback((object s) =>
        {
            count++;
            if (count >= 2)
            {
                are.Set();
            }
        }), null, TimeSpan.FromMilliseconds(100), TimeSpan.FromMilliseconds(Timeout.Infinite) /* not relevant */))
        {
            Assert.False(are.WaitOne(TimeSpan.FromSeconds(1)));
        }
    }
开发者ID:nuskarthik,项目名称:corefx,代码行数:17,代码来源:TimerFiringTests.cs

示例15: Timer_Fires_After_DueTime_AndOn_Period

    public void Timer_Fires_After_DueTime_AndOn_Period()
    {
        int count = 0;
        AutoResetEvent are = new AutoResetEvent(false);

        using (var t = new Timer(new TimerCallback((object s) =>
        {
            count++;
            if (count >= 2)
            {
                are.Set();
            }
        }), null, TimeSpan.FromMilliseconds(250), TimeSpan.FromMilliseconds(50)))
        {
            Assert.True(are.WaitOne(TimeSpan.FromMilliseconds(2000)));
        }
    }
开发者ID:nuskarthik,项目名称:corefx,代码行数:17,代码来源:TimerFiringTests.cs


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