本文整理汇总了C#中System.Threading.WaitHandle.WaitOne方法的典型用法代码示例。如果您正苦于以下问题:C# WaitHandle.WaitOne方法的具体用法?C# WaitHandle.WaitOne怎么用?C# WaitHandle.WaitOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.WaitHandle
的用法示例。
在下文中一共展示了WaitHandle.WaitOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartOnMySignal
static WaitHandle StartOnMySignal(WaitHandle signalWhenReadyToStart, Action callback)
{
var exitHandle = new ManualResetEvent(false);
ThreadPool.QueueUserWorkItem(delegate
{
signalWhenReadyToStart.WaitOne();
try
{
var watch = Stopwatch.StartNew();
while (watch.Elapsed < maxExecutionTime)
{
callback();
}
}
catch (Exception ex)
{
exceptions.Add(ex);
}
finally
{
exitHandle.Set();
}
});
return exitHandle;
}
示例2: ShowDialog
public DialogResult ShowDialog(MobileRemoteUI parentForm, WaitHandle waitResult, AddressSelector.BluetoothDevice device, BluetoothHidWriter hidWriter)
{
_statusLabel.Text = "Connecting...";
_hidWriter = hidWriter;
_waitResult = waitResult;
if (device.Address > 0)
{
_existingMachine.Dock = DockStyle.Fill;
_existingMachine.Visible = true;
_newMachineLabel.Visible = false;
}
else
{
_newMachineLabel.Dock = DockStyle.Fill;
_newMachineLabel.Visible = true;
_existingMachine.Visible = false;
}
timer1.Enabled = true;
if (waitResult.WaitOne(1000, false))
{
//return DialogResult.OK;
}
try
{
return base.ShowDialog(parentForm);
}
finally
{
timer1.Enabled = false;
}
}
示例3: Start
public void Start(WaitHandle waitHandle)
{
var client = new ResbitClient("http://localhost:55672", "guest", "guest");
Console.WriteLine(client.AlivenessTest.Get(""));
waitHandle.WaitOne();
}
示例4: Start
public void Start(WaitHandle waitHandle)
{
var client = new ResbitClient("http://localhost:55672", "guest", "guest");
foreach (var property in (IDictionary<string, object>)client.WhoAmI.Get())
Console.WriteLine(property.Key);
waitHandle.WaitOne();
}
示例5: WaitOne
public static void WaitOne(WaitHandle handle, int timeout = 60 * 1000)
{
bool ok = handle.WaitOne(timeout);
if (!ok)
{
// timeout. Event not signaled in time.
throw new ApplicationException("Condition not reached within timeout.");
}
}
示例6: Wait
private static void Wait(Exception e, WaitHandle g)
{
if (!g.WaitOne(10000))
{
throw new Exception("timed out");
}
if (e != null)
{
throw e;
}
}
示例7: EnReadMemoryLogImpl
/// <summary>
/// 要求がある限りログを読み取ります。無限に列挙し続けます。
/// </summary>
/// <returns></returns>
private static IEnumerable<FFXIVLog> EnReadMemoryLogImpl(WaitHandle wo)
{
if (wo.WaitOne(100)) yield break;
yield return Internal(null, FFXILogMessageType.INTERNAL_START, "## FF14 ログ監視処理開始 ##");
foreach (var ff14 in EnScanProcess()) {
// プロセスを見つけられなかったら5秒待って再検索
if (ff14 == null) {
#if DEBUG
yield return Internal(null, FFXILogMessageType.INTERNAL_WAIT, "FF14プロセス検索:5秒待機");
#endif
if (wo.WaitOne(5000)) yield break;
continue;
}
// ログ領域の検索。見つけられなかったら5秒まって再検索
// 10回試行しても見つからなければ最初からやり直し
yield return Internal(ff14, FFXILogMessageType.INTERNAL_FOUND14, "## FF14 プロセス発見、ログ領域検索開始 ##");
FFXIVLogStatus reader = null;
for (var i = 0; i < 10; i++) {
reader = ff14.SearchLogStatus();
if (reader != null) break;
#if DEBUG
yield return Internal(ff14, FFXILogMessageType.INTERNAL_WAIT, "FF14ログ領域検索:5秒待機");
#endif
if (wo.WaitOne(5000)) yield break;
continue;
}
if (reader == null) continue;
yield return Internal(ff14, FFXILogMessageType.INTERNAL_FOUND_LOG, "## FF14 ログ領域発見、ログ列挙開始 ##");
foreach (var log in reader.EnReadMemoryLog()) {
if (log == null) {
if (wo.WaitOne(10)) yield break;
continue;
}
yield return log;
}
yield return Internal(ff14, FFXILogMessageType.INTERNAL_LOST14, "## FF14 プロセスロスト ##");
}
}
示例8: Start
public void Start(WaitHandle waitHandle)
{
var connectionFactory = new DefaultConnectionFactory(Constants.HostName);
PublisherConfirmsProvider.DeclareExchange(connectionFactory);
var bus = new RogerBus(connectionFactory, new SimpleConsumerContainer(new PublisherConfirmsConsumer()));
bus.Start();
waitHandle.WaitOne();
bus.Dispose();
}
示例9: Start
public void Start(WaitHandle waitHandle)
{
using (var connection = CreateConnection())
using (var model = connection.CreateModel())
{
while (!waitHandle.WaitOne(TimeSpan.FromMilliseconds(100)))
{
model.BasicPublish(Constants.FederationExchangeName, "Routing.Key", null, string.Format("Ciao from {0}", GetType().Name).Bytes());
Console.WriteLine("Message published");
}
}
}
示例10: StartPublishing
private void StartPublishing(IRabbitBus bus, WaitHandle waitHandle)
{
var counter = 0;
while (!waitHandle.WaitOne(10))
{
bus.Publish(new PublisherConfirmsMessage {Counter = ++counter}, persistent: false);
Console.WriteLine("Published message {0}", counter);
}
bus.Dispose();
}
示例11: Run
protected override void Run(WaitHandle shutdownHandle)
{
Console.WriteLine("StandardService, Service started. Waiting for exit event");
while (!shutdownHandle.WaitOne(100))
{
//runs something every 100ms
}
Console.WriteLine("StandardService, Exiting");
}
示例12: WaitOneOrTwoOrAllOthers
public static int WaitOneOrTwoOrAllOthers(WaitHandle one, WaitHandle two, WaitHandle[] others)
{
CodeContract.Requires(one != null);
CodeContract.Requires(two != null);
CodeContract.Requires(others != null && others.Length > 1);
var occurredEventIndex = WaitHandle.WaitTimeout;
var eventSignaled = new ManualResetEvent(false);
var waitOneThread = ThreadUtils.StartBackgroundThread(
() =>
{
try
{
one.WaitOne();
occurredEventIndex = 0;
}
finally
{
eventSignaled.Set();
}
});
var waitTwoThread = ThreadUtils.StartBackgroundThread(
() =>
{
try
{
two.WaitOne();
occurredEventIndex = 1;
}
finally
{
eventSignaled.Set();
}
});
var waitOthersThread = ThreadUtils.StartBackgroundThread(
() =>
{
try
{
WaitHandle.WaitAll(others);
occurredEventIndex = 2;
}
finally
{
eventSignaled.Set();
}
});
eventSignaled.WaitOne();
waitOneThread.SafeAbort();
waitTwoThread.SafeAbort();
waitOthersThread.SafeAbort();
return occurredEventIndex;
}
示例13: Run
public static void Run(WaitHandle exitHandle)
{
var serviceHost = new ServiceHost(new UtilWcfService());
serviceHost.AddServiceEndpoint(typeof (IUtilWcfService), new NetTcpBinding(SecurityMode.None){TransferMode = TransferMode.Streamed}, "net.tcp://localhost:54321");
Console.WriteLine("WCF SERVER: Open");
serviceHost.Open();
Console.WriteLine("WCF SERVER: Wait");
exitHandle.WaitOne();
Console.WriteLine("WCF SERVER: Close");
serviceHost.Close();
Console.WriteLine("WCF SERVER: Done");
}
示例14: Start
public void Start(WaitHandle waitHandle)
{
using (var connection = Helpers.CreateConnection())
using (var model = connection.CreateModel())
{
model.ExchangeDeclare(Constants.ExchangeName, ExchangeType.Topic, false, true, null);
while (!waitHandle.WaitOne(TimeSpan.FromSeconds(5)))
{
var routingKey = CreateRoutingKey();
model.BasicPublish(Constants.ExchangeName, routingKey, null, GetBody(routingKey));
Console.WriteLine("Published {0} message", routingKey);
}
}
}
示例15: Start
public void Start(WaitHandle waitHandle)
{
using (var connection = Helpers.CreateConnection())
using (var channel = connection.CreateModel())
{
channel.QueueDeclare("hello", false, false, false, null);
Console.WriteLine("Waiting for messages...");
var consumer = new EventingBasicConsumer();
consumer.Received += ConsumerOnReceived;
channel.BasicConsume(Constants.QueueName, true, consumer);
waitHandle.WaitOne();
}
}