本文整理汇总了C#中System.Threading.AutoResetEvent.WaitOne方法的典型用法代码示例。如果您正苦于以下问题:C# System.Threading.AutoResetEvent.WaitOne方法的具体用法?C# System.Threading.AutoResetEvent.WaitOne怎么用?C# System.Threading.AutoResetEvent.WaitOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.AutoResetEvent
的用法示例。
在下文中一共展示了System.Threading.AutoResetEvent.WaitOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test
public void Test()
{
System.Threading.AutoResetEvent evt = new System.Threading.AutoResetEvent(false);
Packets.LicensePlatePacket p = null;
int count = 0;
Manager mnger = new Manager(new PacketSplitter());
var parser = new Parsers.LicensePlateParser();
parser.Handler += licensePlate =>
{
System.Diagnostics.Debug.WriteLine(licensePlate.LicensePlate.LicenseNumber);
p = licensePlate;
++count;
if (count > 1000)
{
evt.Set();
}
};
mnger.Parsers.Add(parser);
mnger.Start();
evt.WaitOne(10000);
mnger.Stop();
Assert.IsNotNull(p);
}
示例2: Run
public static void Run(string[] args)
{
if (args.Length == 0)
{
Command.Application application = new Command.Application();
IDisposable telnet = Parser.Listen(application, "telnet://:23");
IDisposable tcp = Parser.Listen(application, "tcp://:20");
IDisposable console = Parser.Listen(application, "console:///");
}
else
{
Application application = new Application();
Settings.Module settings = new Settings.Module()
{
//Header = "<link href=\"resources/settings.css\" rel=\"stylesheet\" type=\"text/css\"/>\n <link href=\"resources/settings.css\" rel=\"stylesheet\" type=\"text/css\"/>",
};
settings.Load("loader", new Loader(settings));
settings.Load("old.object", new Object());
settings.Load("application", new Command.Application());
application.Load(settings);
application.Start();
System.Threading.AutoResetEvent wait = new System.Threading.AutoResetEvent(false);
application.OnClosed += () => wait.Set();
wait.WaitOne();
//application.Execute();
}
}
示例3: DeviceLocator_Notifications_DoesNotRaiseDeviceAvailableIfDisposed
public void DeviceLocator_Notifications_DoesNotRaiseDeviceAvailableIfDisposed()
{
var server = new MockCommsServer();
var deviceLocator = new MockDeviceLocator(server);
DiscoveredSsdpDevice device = null;
bool newlyDiscovered = false;
var receivedNotification = false;
using (var eventSignal = new System.Threading.AutoResetEvent(false))
{
deviceLocator.DeviceAvailable += (sender, args) =>
{
device = args.DiscoveredDevice;
newlyDiscovered = args.IsNewlyDiscovered;
receivedNotification = true;
};
deviceLocator.StartListeningForNotifications();
server.MockReceiveBroadcast(GetMockAliveNotification());
server.Dispose();
eventSignal.WaitOne(1000);
}
Assert.IsFalse(receivedNotification);
}
示例4: flushGraphics
/// </summary>
/// <param name="rect"></param>
internal void flushGraphics(Rectangle rect)
{
using (System.Threading.AutoResetEvent are = new System.Threading.AutoResetEvent(false))
{
SilverlightImplementation.dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
IList<AsyncOp> tmp = renderingOperations;
renderingOperations = pendingRenderingOperations;
pendingRenderingOperations = tmp;
if (rect == null)
{
_screen.Invalidate();
}
else
{
_graphics.clip = rect;
_graphics.destination.setClip(rect);
_screen.Invalidate();
}
_graphics.destination.setAlpha(255);
_graphics.destination.setColor(0);
are.Set();
}).AsTask().GetAwaiter().GetResult();
are.WaitOne();
}
}
示例5: Should_be_able_to_configure_EasyNetQ_to_allow_message_with_a_blank_type_field
public void Should_be_able_to_configure_EasyNetQ_to_allow_message_with_a_blank_type_field()
{
var are = new System.Threading.AutoResetEvent(false);
var validation = new NullMessageValidator();
var bus = RabbitHutch.CreateBus("host=localhost", r =>
r.Register<IMessageValidationStrategy>(x => validation));
bus.Subscribe<MyMessage>("null_validation_test", message =>
{
Console.Out.WriteLine("Got message: {0}", message.Text);
are.Set();
});
// now use the basic client API to publish some JSON to the message type exchange ...
var factory = new RabbitMQ.Client.ConnectionFactory
{
HostName = "localhost"
};
using (var connection = factory.CreateConnection())
using (var channel = connection.CreateModel())
{
const string exchange = "EasyNetQ_Tests_MyMessage:EasyNetQ_Tests";
const string routingKey = "#";
const string bodyString = "{ Text: \"Hello from Mr Raw :)\" }";
var body = System.Text.Encoding.UTF8.GetBytes(bodyString);
var properties = channel.CreateBasicProperties();
channel.BasicPublish(exchange, routingKey, properties, body);
}
are.WaitOne(1000);
}
示例6: Main
static void Main(string[] args)
{
// args:
// 0: jid, name
// 1: passwd
// 2: mcu jid
// 3: cmd
// 4: cmd_options
if (args.Length == 5)
{
string xmpp_domain = Environment.GetEnvironmentVariable("xmpp_domain");
if (xmpp_domain == null)
xmpp_domain = "app.zonekey.com.cn";
cs_zkrobot.client.NormalUser user = cs_zkrobot.client.UserFactory.makeNormal();
if (!user.login(args[0] + "@" + xmpp_domain, args[1]))
{
System.Console.WriteLine("login err: " + args[0] + "@" + xmpp_domain);
}
else
{
System.Console.WriteLine("req: to:" + args[2] + ", cmd=" + args[3] + ", options=" + args[4]);
System.Threading.AutoResetEvent comp_evt = new System.Threading.AutoResetEvent(false);
user.async_request(args[2] + "@" + xmpp_domain, args[3], args[4], cb_response, comp_evt);
comp_evt.WaitOne();
user.logout();
}
}
}
示例7: GivenIHaveAServer
public void GivenIHaveAServer()
{
var wait = new System.Threading.AutoResetEvent(false);
var server = ScenarioContext.Current.Get<System.ServiceModel.ServiceHost>();
server.Opened += (sender, args) => wait.Set();
server.Open();
Assert.IsTrue(wait.WaitOne(TimeSpan.FromSeconds(1)));
}
示例8: GlibSync
// Sync up with the GLib thread. Should be called after the
// name, role, or parent are changed in UiaAtkBridge when
// checking for events, since we defer to an idle
// handler to call atk to avoid deadlock when atk
// emits signals. Called by RunInGuiThread in
// UiaAtkBridge.
public static void GlibSync ()
{
System.Threading.AutoResetEvent sync = new System.Threading.AutoResetEvent (false);
GLib.Timeout.Add (0, new GLib.TimeoutHandler (delegate {
sync.Set ();
return false;
}));
sync.WaitOne ();
sync.Close ();
}
示例9: Execute
/// <summary>
/// Exectute the command
/// </summary>
/// <param name="args"></param>
/// <param name="fromAgentID"></param>
/// <returns></returns>
public override string Execute(string[] args, UUID fromAgentID)
{
if (args.Length < 1)
{
return "Usage: viewnote [notecard asset uuid]";
}
UUID note;
if (!UUID.TryParse(args[0], out note))
{
return "First argument expected agent UUID.";
}
System.Threading.AutoResetEvent waitEvent = new System.Threading.AutoResetEvent(false);
System.Text.StringBuilder result = new System.Text.StringBuilder();
// define a delegate to handle the reply
AssetManager.AssetReceivedCallback del = delegate(AssetDownload transfer, Asset asset)
{
if (transfer.Success)
{
result.AppendFormat("Raw Notecard Data: " + System.Environment.NewLine + " {0}", Utils.BytesToString(asset.AssetData));
waitEvent.Set();
}
};
// verify asset is loaded in store
if (Client.Inventory.Store.Contains(note))
{
// retrieve asset from store
InventoryItem ii = (InventoryItem)Client.Inventory.Store[note];
// subscribe to reply event
Client.Assets.OnAssetReceived += del;
// make request for asset
Client.Assets.RequestInventoryAsset(ii, true);
// wait for reply or timeout
if (!waitEvent.WaitOne(10000, false))
{
result.Append("Timeout waiting for notecard to download.");
}
// unsubscribe from reply event
Client.Assets.OnAssetReceived -= del;
}
else
{
result.Append("Cannot find asset in inventory store, use 'i' to populate store");
}
// return results
return result.ToString();
}
示例10: GivenIHaveAClient
public void GivenIHaveAClient(string endpoint)
{
var wait = new System.Threading.AutoResetEvent(false);
var client = new Wcf.ServiceClient(endpoint);
client.InnerChannel.Opened += (sender, args) => wait.Set();
client.Open();
Assert.IsTrue(wait.WaitOne(TimeSpan.FromSeconds(1)));
ScenarioContext.Current.Set(client);
}
示例11: compile
public static Assembly compile(this string pathToFileToCompile, bool generateDebugSymbols)
{
PublicDI.CurrentScript = pathToFileToCompile;
var csharpCompiler = new CSharp_FastCompiler();
csharpCompiler.generateDebugSymbols= generateDebugSymbols;
var compileProcess = new System.Threading.AutoResetEvent(false);
csharpCompiler.compileSourceCode(pathToFileToCompile.contents());
csharpCompiler.onCompileFail = () => compileProcess.Set();
csharpCompiler.onCompileOK = () => compileProcess.Set();
compileProcess.WaitOne();
return csharpCompiler.assembly();
}
示例12: Execute
public override string Execute(string[] args, Guid fromAgentID)
{
System.Threading.AutoResetEvent waitBalance = new System.Threading.AutoResetEvent(false);
AgentManager.BalanceCallback del = delegate(int balance) { waitBalance.Set(); };
Client.Self.OnBalanceUpdated += del;
Client.Self.RequestBalance();
String result = "Timeout waiting for balance reply";
if (waitBalance.WaitOne(10000, false))
{
result = Client.ToString() + " has L$: " + Client.Self.Balance;
}
Client.Self.OnBalanceUpdated -= del;
return result;
}
示例13: compile_CodeSnippet
public static Assembly compile_CodeSnippet(this string codeSnipptet, bool generateDebugSymbols)
{
//Note we can't use the precompiled engines here since there is an issue of the resolution of this code dependencies
var csharpCompiler = new CSharp_FastCompiler();
csharpCompiler.generateDebugSymbols= generateDebugSymbols;
var compileProcess = new System.Threading.AutoResetEvent(false);
//csharpCompiler.compileSourceCode(pathToFileToCompile.contents());
csharpCompiler.compileSnippet(codeSnipptet);
csharpCompiler.onCompileFail = () => compileProcess.Set();
csharpCompiler.onCompileOK = () => compileProcess.Set();
compileProcess.WaitOne();
var assembly = csharpCompiler.assembly();
return assembly;
}
示例14: Execute
public override string Execute(string[] args, UUID fromAgentID)
{
System.Threading.AutoResetEvent waitBalance = new System.Threading.AutoResetEvent(false);
EventHandler<BalanceEventArgs> del = delegate(object sender, BalanceEventArgs e) { waitBalance.Set(); };
Client.Self.MoneyBalance += del;
Client.Self.RequestBalance();
String result = "Timeout waiting for balance reply";
if (waitBalance.WaitOne(10000, false))
{
result = Client.ToString() + " has L$: " + Client.Self.Balance;
}
Client.Self.MoneyBalance -= del;
return result;
}
示例15: NtpClient_DefaultServer_GetsNonNullResponse
public void NtpClient_DefaultServer_GetsNonNullResponse()
{
_GotResultSignal = new System.Threading.AutoResetEvent(false);
var client = new Yort.Ntp.NtpClient();
try
{
client.TimeReceived += Client_TimeReceived;
client.ErrorOccurred += Client_ErrorOccurred;
client.BeginRequestTime();
_GotResultSignal.WaitOne(1000);
Assert.AreNotEqual(null, _Result);
}
finally
{
client.TimeReceived -= this.Client_TimeReceived;
client.ErrorOccurred -= this.Client_ErrorOccurred;
}
}