本文整理汇总了C#中AutoResetEvent.Reset方法的典型用法代码示例。如果您正苦于以下问题:C# AutoResetEvent.Reset方法的具体用法?C# AutoResetEvent.Reset怎么用?C# AutoResetEvent.Reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AutoResetEvent
的用法示例。
在下文中一共展示了AutoResetEvent.Reset方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
}
}
示例2: PosTest1
public bool PosTest1()
{
bool retVal = true;
AutoResetEvent are;
long ticksBefore;
long ticksAfter;
TestLibrary.TestFramework.BeginScenario("PosTest1: AutoResetEvent.Reset()");
try
{
// true means that the initial state should be signaled
are = new AutoResetEvent(true);
if (!are.Reset())
{
TestLibrary.TestFramework.LogError("001", "AutoResetEvent.Reset() failed");
retVal = false;
}
ticksBefore = DateTime.Now.Ticks;
// 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 signaled it will not wait long enough");
are.WaitOne(c_MILLISECONDS_TOWAIT);
ticksAfter = DateTime.Now.Ticks;
if (c_DELTA < Math.Abs((ticksAfter - ticksBefore) - (c_MILLISECONDS_TOWAIT*10000)))
{
TestLibrary.TestFramework.LogError("002", "AutoResetEvent did not wait long enough... this implies that the parameter was not respected.");
TestLibrary.TestFramework.LogError("002", " WaitTime=" + (ticksAfter-ticksBefore) + " (ticks)");
TestLibrary.TestFramework.LogError("002", " Execpted=" + (c_MILLISECONDS_TOWAIT*10000) + " (ticks)");
TestLibrary.TestFramework.LogError("002", " Acceptable Delta=" + c_DELTA + " (ticks)");
retVal = false;
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
retVal = false;
}
return retVal;
}
示例3: Main
//.........这里部分代码省略.........
for (int i = 0; i < ipAddresses.Length; i++) {
if (i > 0)
procArgs.Append (',');
procArgs.Append (ipAddresses [i].ToString ());
}
proc.StartInfo.FileName = mtouch;
proc.StartInfo.Arguments = procArgs.ToString ();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs e) {
lock (output) {
output.Append ("[mtouch stderr] ");
output.AppendLine (e.Data);
}
};
proc.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e) {
lock (output) {
output.Append ("[mtouch stdout] ");
output.AppendLine (e.Data);
}
};
proc.Start ();
proc.BeginErrorReadLine ();
proc.BeginOutputReadLine ();
proc.WaitForExit ();
if (proc.ExitCode != 0)
listener.Cancel ();
Console.WriteLine (output.ToString ());
}
});
}
var lastErrorDataReceived = new AutoResetEvent (true);
var lastOutDataReceived = new AutoResetEvent (true);
if (launchsim != null) {
lastErrorDataReceived.Reset ();
lastOutDataReceived.Reset ();
ThreadPool.QueueUserWorkItem ((v) => {
{
proc = new Process ();
int pid = 0;
StringBuilder output = new StringBuilder ();
StringBuilder procArgs = new StringBuilder ();
string sdk_root = Environment.GetEnvironmentVariable ("XCODE_DEVELOPER_ROOT");
if (!String.IsNullOrEmpty (sdk_root))
procArgs.Append ("--sdkroot ").Append (sdk_root);
procArgs.Append (" --launchsim ");
procArgs.Append (Quote (launchsim));
if (!string.IsNullOrEmpty (device_type))
procArgs.Append (" --device ").Append (device_type);
procArgs.Append (" -argument=-connection-mode -argument=none");
procArgs.Append (" -argument=-app-arg:-autostart");
procArgs.Append (" -argument=-app-arg:-autoexit");
procArgs.Append (" -argument=-app-arg:-enablenetwork");
procArgs.Append (" -argument=-app-arg:-hostname:127.0.0.1");
procArgs.AppendFormat (" -argument=-app-arg:-hostport:{0}", listener.Port);
foreach (var arg in mtouch_arguments)
procArgs.Append (" ").Append (arg);
proc.StartInfo.FileName = mtouch;
proc.StartInfo.Arguments = procArgs.ToString ();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardInput = true;
示例4: InterruptTest
public static void InterruptTest()
{
// Interrupting a thread that is not blocked does not do anything, but once the thread starts blocking, it gets
// interrupted
var threadReady = new AutoResetEvent(false);
var continueThread = new AutoResetEvent(false);
bool continueThreadBool = false;
Action waitForThread;
var t =
ThreadTestHelpers.CreateGuardedThread(out waitForThread, () =>
{
threadReady.Set();
ThreadTestHelpers.WaitForConditionWithoutBlocking(() => Volatile.Read(ref continueThreadBool));
threadReady.Set();
Assert.Throws<ThreadInterruptedException>(() => continueThread.CheckedWait());
});
t.IsBackground = true;
t.Start();
threadReady.CheckedWait();
t.Interrupt();
Assert.False(threadReady.WaitOne(ExpectedTimeoutMilliseconds));
Volatile.Write(ref continueThreadBool, true);
waitForThread();
// Interrupting a dead thread does nothing
t.Interrupt();
// Interrupting an unstarted thread causes the thread to be interrupted after it is started and starts blocking
t = ThreadTestHelpers.CreateGuardedThread(out waitForThread, () =>
Assert.Throws<ThreadInterruptedException>(() => continueThread.CheckedWait()));
t.IsBackground = true;
t.Interrupt();
t.Start();
waitForThread();
// A thread that is already blocked on a synchronization primitive unblocks immediately
continueThread.Reset();
t = ThreadTestHelpers.CreateGuardedThread(out waitForThread, () =>
Assert.Throws<ThreadInterruptedException>(() => continueThread.CheckedWait()));
t.IsBackground = true;
t.Start();
ThreadTestHelpers.WaitForCondition(() => (t.ThreadState & ThreadState.WaitSleepJoin) != 0);
t.Interrupt();
waitForThread();
}
示例5: Inventory_OnObjectOffered
bool Inventory_OnObjectOffered(InstantMessage offerDetails, AssetType type, UUID objectID, bool fromTask)
{
AutoResetEvent ObjectOfferEvent = new AutoResetEvent(false);
ResponseType object_offer_result=ResponseType.Yes;
string msg = "";
ResponseType result;
if (!fromTask)
msg = "The user "+offerDetails.FromAgentName + " has offered you\n" + offerDetails.Message + "\n Which is a " + type.ToString() + "\nPress Yes to accept or no to decline";
else
msg = "The object "+offerDetails.FromAgentName + " has offered you\n" + offerDetails.Message + "\n Which is a " + type.ToString() + "\nPress Yes to accept or no to decline";
Application.Invoke(delegate {
ObjectOfferEvent.Reset();
Gtk.MessageDialog md = new MessageDialog(MainClass.win, DialogFlags.Modal, MessageType.Other, ButtonsType.YesNo, false, msg);
result = (ResponseType)md.Run();
object_offer_result=result;
md.Destroy();
ObjectOfferEvent.Set();
});
ObjectOfferEvent.WaitOne(1000*3600,false);
if (object_offer_result == ResponseType.Yes)
{
if(OnInventoryAccepted!=null)
{
OnInventoryAccepted(type,objectID);
}
return true;
}
else
{
return false;
}
}