本文整理汇总了C#中System.Threading.ManualResetEvent.WaitOne方法的典型用法代码示例。如果您正苦于以下问题:C# System.Threading.ManualResetEvent.WaitOne方法的具体用法?C# System.Threading.ManualResetEvent.WaitOne怎么用?C# System.Threading.ManualResetEvent.WaitOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.ManualResetEvent
的用法示例。
在下文中一共展示了System.Threading.ManualResetEvent.WaitOne方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConnectionManagerAddsNewServicesFromServiceDiscovery
public void ConnectionManagerAddsNewServicesFromServiceDiscovery()
{
var manualResetEvent = new System.Threading.ManualResetEvent(false);
var serviceUri1 = new ServiceUri() { Address = "1" };
var serviceUri2 = new ServiceUri() { Address = "2" };
Dictionary<ServiceUri, PerformanceStatistics> services
= new Dictionary<ServiceUri, PerformanceStatistics>()
{
{serviceUri1, new PerformanceStatistics()},
{serviceUri2, new PerformanceStatistics()}
};
var serviceDiscoveryMock = new Mock<IServiceDiscovery>(MockBehavior.Strict);
serviceDiscoveryMock.Setup(sd => sd.GetPerformanceStatistics()).Returns(() => services).Callback(() => manualResetEvent.Set());
var manager = new ConnectionManager(remoteService: null, listener: null,
serviceDiscovery: serviceDiscoveryMock.Object,
serviceDiscoveryPeriod: new TimeSpan(days: 0, hours: 0, minutes: 0, seconds: 0, milliseconds: 10));
manualResetEvent.WaitOne();
manager.RemoteServices.Count().ShouldBe(2);
services.Add(new ServiceUri(), new PerformanceStatistics());
manualResetEvent.Reset();
manualResetEvent.WaitOne();
manager.RemoteServices.Count().ShouldBe(3);
}
示例2: SendMessage_Test
public void SendMessage_Test()
{
RequestMessage message = new RequestMessage()
{
Device = "test",
Level = MessageLevel.High,
Message = "test",
Source = "unitest",
Title = "test"
};
ResponseMessage resmessage = CatsAgent.SendMessage(message);
var t1 = resmessage.Message;
var t2 = resmessage.Result;
Assert.IsTrue(t1.Length > 0);
Assert.AreEqual(t2, MessageSendingResult.Succeed);
System.Threading.ManualResetEvent hand = new System.Threading.ManualResetEvent(false);
CatsAgent.SendMessageAsync(message, new
Action<ResponseMessage>((ar) => { hand.Set(); }));
hand.WaitOne();
}
示例3: Scan
public override Task<Result> Scan(MobileBarcodeScanningOptions options)
{
return Task.Factory.StartNew(new Func<Result>(() =>
{
var scanResultResetEvent = new System.Threading.ManualResetEvent(false);
Result result = null;
//Navigate: /ZxingSharp.WindowsPhone;component/Scan.xaml
ScanPage.ScanningOptions = options;
ScanPage.ResultFoundAction = (r) =>
{
result = r;
scanResultResetEvent.Set();
};
ScanPage.UseCustomOverlay = this.UseCustomOverlay;
ScanPage.CustomOverlay = this.CustomOverlay;
ScanPage.TopText = TopText;
ScanPage.BottomText = BottomText;
Dispatcher.BeginInvoke(() =>
{
((Microsoft.Phone.Controls.PhoneApplicationFrame)Application.Current.RootVisual).Navigate(
new Uri("/ZXingNetMobile;component/ScanPage.xaml", UriKind.Relative));
});
scanResultResetEvent.WaitOne();
return result;
}));
}
示例4: Scan
public override Task<Result> Scan(MobileBarcodeScanningOptions options)
{
var rootFrame = RootFrame ?? Window.Current.Content as Frame ?? ((FrameworkElement) Window.Current.Content).GetFirstChildOfType<Frame>();
var dispatcher = Dispatcher ?? Window.Current.Dispatcher;
return Task.Factory.StartNew(new Func<Result>(() =>
{
var scanResultResetEvent = new System.Threading.ManualResetEvent(false);
Result result = null;
ScanPage.ScanningOptions = options;
ScanPage.ResultFoundAction = (r) =>
{
result = r;
scanResultResetEvent.Set();
};
ScanPage.UseCustomOverlay = this.UseCustomOverlay;
ScanPage.CustomOverlay = this.CustomOverlay;
ScanPage.TopText = TopText;
ScanPage.BottomText = BottomText;
dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
rootFrame.Navigate(typeof(ScanPage));
});
scanResultResetEvent.WaitOne();
return result;
}));
}
示例5: ExecuteAndWaitForSSHCommand
private static void ExecuteAndWaitForSSHCommand(string IPAddress,string command)
{
var handle = new System.Threading.ManualResetEvent(false);
var helper = new SshCommandHelper(IPAddress, handle);
helper.WriteSSHCommand(command, true);
handle.WaitOne();
}
示例6: Main
static void Main()
{
System.Threading.ManualResetEvent close = new System.Threading.ManualResetEvent(false);
SystemEvents.SessionEnding += (object sender, SessionEndingEventArgs e) =>
close.Set();
BaseClass();
close.WaitOne();
}
示例7: Parse
static void Parse()
{
var e = new System.Threading.ManualResetEvent(false);
Console.WriteLine ("Parsing...");
GlobalParseCache.BeginAddOrUpdatePaths (new[]{ srcDir }, false, (ea) => {
Console.WriteLine ("Finished parsing. {0} files. {1} ms.", ea.FileAmount, ea.ParseDuration);
e.Set();
});
e.WaitOne ();
}
示例8: RunAsync
public async Task RunAsync ( Action act )
{
await Task.Run ( ( ) =>
{
System.Threading.ManualResetEvent evt = new System.Threading.ManualResetEvent ( false );
m_dispatcher.BeginInvoke ( ( ) =>
{
act ( );
evt.Set ( );
} );
evt.WaitOne ( );
} );
}
示例9: Scan
public override Task<Result> Scan (MobileBarcodeScanningOptions options)
{
return Task.Factory.StartNew(() => {
try
{
var scanResultResetEvent = new System.Threading.ManualResetEvent(false);
Result result = null;
this.appController.InvokeOnMainThread(() => {
// Free memory first and release resources
if (viewController != null)
{
viewController.Dispose();
viewController = null;
}
viewController = new ZxingCameraViewController(options, this);
viewController.BarCodeEvent += (BarCodeEventArgs e) => {
viewController.DismissViewController();
result = e.BarcodeResult;
scanResultResetEvent.Set();
};
viewController.Canceled += (sender, e) => {
viewController.DismissViewController();
scanResultResetEvent.Set();
};
appController.PresentViewController(viewController, true, () => { });
});
scanResultResetEvent.WaitOne();
return result;
}
catch (Exception ex)
{
return null;
}
});
}
示例10: RunUpdate
public void RunUpdate()
{
var u = Updater.Instance;
var waitHandler = new System.Threading.ManualResetEvent(false);
u.NoUpdatesFound += (s, e) => waitHandler.Set();
u.Error += (s, e) => waitHandler.Set();
u.ExternalUpdateStarted += (s, e) => waitHandler.Set();
u.UpdateCancelled += (s, e) => waitHandler.Set();
Updater.CheckUpdateSimple();
waitHandler.WaitOne();
}
示例11: Main
static void Main(string[] args)
{
//Load initial settings
Logger.Logger.Get("Runner").Message("App started");
//Logger.Logger.Get().Message("App started");
WorkerProcess.GetInstance().Process();
System.Threading.ManualResetEvent _quitEvent = new System.Threading.ManualResetEvent(false);
Console.CancelKeyPress += (sender, eArgs) => {
_quitEvent.Set(); eArgs.Cancel = true;
};
_quitEvent.WaitOne();
}
示例12: Application_Start
protected void Application_Start()
{
// AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
// Automatically delete timed out sessions in our table.
_reaperQuit = new System.Threading.ManualResetEvent(false);
_reaper = new System.Threading.Thread(new System.Threading.ThreadStart(() => {
while (!_reaperQuit.WaitOne(30000)) {
Climoo.Session.SessionManager.GrimReaper();
}
}));
_reaper.Start();
Game.WorldData.Init();
}
示例13: Wait
/// <summary>
/// Call to wait for an event that is newer than the current known event
/// </summary>
/// <param name="eventId">The last known event id</param>
/// <param name="milliseconds">The number of milliseconds to block</param>
/// <returns>The current event id</returns>
public long Wait(long eventId, int milliseconds)
{
System.Threading.ManualResetEvent mre;
lock (m_lock)
{
//If a newer event has already occured, return immediately
if (eventId != m_eventNo)
return m_eventNo;
//Otherwise register this thread as waiting
mre = new System.Threading.ManualResetEvent(false);
m_waitQueue.Enqueue(mre);
}
//Wait until we are signalled or the time has elapsed
mre.WaitOne(milliseconds, false);
return m_eventNo;
}
示例14: AskForConnectionAsync
internal async Task<Connection> AskForConnectionAsync()
{
using (var closedEvent = new System.Threading.ManualResetEvent(false))
{
var dialog = new ConnectionDialog();
dialog.Closed += (sender, e) =>
{
closedEvent.Set();
};
dialog.Show();
await Task.Run(new Action(() => closedEvent.WaitOne()));
if (dialog.Ok ?? false)
return dialog.Connection;
else
return null;
}
}
示例15: GetIsCertificateTrusted
public bool GetIsCertificateTrusted (string uri, string certificateFingerprint)
{
bool value;
if (!TrustedCertificates.TryGetValue (certificateFingerprint, out value)) {
using (var handle = new System.Threading.ManualResetEvent (false)) {
Gtk.Application.Invoke (delegate {
value = MessageService.AskQuestion (
"Untrusted HTTP certificate detected",
string.Format ("Do you want to temporarily trust this certificate in order to" +
" connect to the server at {0}?", uri),
AlertButton.Yes, AlertButton.No) == AlertButton.Yes;
TrustedCertificates [certificateFingerprint] = value;
handle.Set ();
});
handle.WaitOne ();
}
}
return value;
}