本文整理汇总了C#中System.Threading.EventWaitHandle.Set方法的典型用法代码示例。如果您正苦于以下问题:C# EventWaitHandle.Set方法的具体用法?C# EventWaitHandle.Set怎么用?C# EventWaitHandle.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.EventWaitHandle
的用法示例。
在下文中一共展示了EventWaitHandle.Set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string[] args)
{
var done = new EventWaitHandle(false, EventResetMode.AutoReset);
var yield = new Thread(
new ParameterizedThreadStart(
data =>
{
Console.WriteLine(new { data });
done.Set();
}
)
);
Console.WriteLine("before wait " + DateTime.Now);
// Additional information: Thread has not been started.
done.WaitOne(2100);
Console.WriteLine("after wait " + DateTime.Now);
yield.Start(new { foo = "bar" });
done.WaitOne();
Console.WriteLine("done");
CLRProgram.CLRMain();
}
示例2: StartMission
public void StartMission(string missionName)
{
var down = Program.Downloader.GetResource(DownloadType.MISSION, missionName);
if (down == null)
{
//okay Mission exist, but lets check for dependency!
down = Program.Downloader.GetDependenciesOnly(missionName);
}
var engine = Program.Downloader.GetResource(DownloadType.ENGINE, Program.TasClient.ServerWelcome.Engine ?? GlobalConst.DefaultEngineOverride);
var metaWait = new EventWaitHandle(false, EventResetMode.ManualReset);
Mod modInfo = null;
Program.MetaData.GetModAsync(missionName,
mod =>
{
if (!mod.IsMission)
{
Program.MainWindow.InvokeFunc(() => { WarningBar.DisplayWarning(string.Format("{0} is not a valid mission", missionName)); });
}
else modInfo = mod;
metaWait.Set();
},
error =>
{
Program.MainWindow.InvokeFunc(() =>
{
WarningBar.DisplayWarning(string.Format("Download of metadata failed: {0}", error.Message));
//container.btnStop.Enabled = true;
});
metaWait.Set();
});
var downloads = new List<Download>() { down, engine }.Where(x => x != null).ToList();
if (downloads.Count > 0)
{
var dd = new WaitDownloadDialog(downloads);
if (dd.ShowDialog(Program.MainWindow) == DialogResult.Cancel)
{
Program.MainWindow.InvokeFunc(() => Program.NotifySection.RemoveBar(this));
return;
}
}
metaWait.WaitOne();
var spring = new Spring(Program.SpringPaths);
spring.RunLocalScriptGame(modInfo.MissionScript, Program.TasClient.ServerWelcome.Engine ?? GlobalConst.DefaultEngineOverride);
var cs = GlobalConst.GetContentService();
cs.NotifyMissionRun(Program.Conf.LobbyPlayerName, missionName);
spring.SpringExited += (o, args) => RecordMissionResult(spring, modInfo);
Program.MainWindow.InvokeFunc(() => Program.NotifySection.RemoveBar(this));
}
示例3: Main
static void Main(string[] args)
{
// Create a IPC wait handle with a unique identifier.
bool createdNew;
var waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, "ImperatorWaitHandle", out createdNew);
// If the handle was already there, inform the other process to exit itself.
// Afterwards we'll also die.
if (!createdNew)
{
Console.WriteLine("Found other Imperator process. Requesting stop...");
waitHandle.Set();
Console.WriteLine("Informer exited.");
return;
}
Console.WriteLine("Initializing Container...");
var container = new ContainerInitializer().Initialize();
Console.WriteLine("Connecting to UI...");
var hubClient = container.GetInstance<IHubClient>();
hubClient.OpenConnection();
Console.WriteLine("Connected");
Console.WriteLine("Initializing Imperator...");
var i = container.GetInstance<Imperator>();
i.InitializeConfig();
i.StartImperator();
waitHandle.WaitOne();
Console.WriteLine("Closing Imperator...");
}
示例4: DoubleLaunchLocker
public DoubleLaunchLocker(string signalId, string waitId, bool force = false)
{
_force = force;
SignalId = signalId;
WaitId = waitId;
bool isNew;
_signalHandler = new EventWaitHandle(false, EventResetMode.AutoReset, signalId, out isNew);
if (!isNew)
{
Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
bool terminate = false;
if (!force && !RequestConfirmation())
terminate = true;
if (!terminate)
{
_waitHandler = new EventWaitHandle(false, EventResetMode.AutoReset, waitId);
if (_signalHandler.Set())
terminate = !_waitHandler.WaitOne(TIMEOUT);
else
terminate = true;
}
if (terminate)
{
TryShutdown();
ForceShutdown();
}
else
Application.Current.ShutdownMode = ShutdownMode.OnLastWindowClose;
}
ThreadPool.QueueUserWorkItem(WaitingHandler, waitId);
}
示例5: Controller
public Controller(BlockingMediator mediator)
{
_signal = new AutoResetEvent(false);
mediator.AddSignal(_signal);
dynamic config = ConfigurationManager.GetSection("delays");
var delays = new Dictionary<MessageType, int>();
foreach (string name in config)
{
delays[Hearts.Utility.Enum.Parse<MessageType>(name)] =
int.Parse(config[name]);
}
foreach (var type in Hearts.Utility.Enum.GetValues<MessageType>())
{
var key = type;
mediator.Subscribe(type, ignore =>
{
if (delays.ContainsKey(key))
{
Thread.Sleep(delays[key]);
}
_signal.Reset();
if (!IsBlocking)
{
ThreadPool.QueueUserWorkItem(_ => _signal.Set());
}
});
}
}
示例6: Should_be_able_to_cancel_message_reception_with_a_cancellation_token
public void Should_be_able_to_cancel_message_reception_with_a_cancellation_token()
{
const string mmfName = "Local\\test";
var message = "not null";
var messageCancelled = new EventWaitHandle(false, EventResetMode.ManualReset, mmfName + "_MessageCancelled");
messageCancelled.Set();
using (var messageReceiver = new MemoryMappedFileMessageReceiver(mmfName))
using (var cancellationTokenSource = new CancellationTokenSource())
{
var task = new Task(() => message = messageReceiver.ReceiveMessage(ReadString, cancellationTokenSource.Token));
task.Start();
var isSet = true;
while (isSet)
isSet = messageCancelled.WaitOne(0);
cancellationTokenSource.Cancel();
task.Wait();
message.ShouldBeNull();
}
}
示例7: AbsoluteTimerWaitHandle
public AbsoluteTimerWaitHandle(DateTimeOffset dueTime)
{
_dueTime = dueTime;
_eventWaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
SafeWaitHandle = _eventWaitHandle.SafeWaitHandle;
var dueSpan = (_dueTime - DateTimeOffset.Now);
var period = new TimeSpan(dueSpan.Ticks / 10);
if (dueSpan < TimeSpan.Zero)
{
_eventWaitHandle.Set();
}
else
{
_timer = new Timer(period.TotalMilliseconds)
{
AutoReset = false,
};
_timer.Elapsed += TimerOnElapsed;
_timer.Start();
}
}
示例8: Waiter
public Waiter(TimeSpan? interval = null)
{
_waitHandle = new AutoResetEvent(false);
_timer = new System.Timers.Timer();
_timer.Elapsed += (sender, args) => _waitHandle.Set();
SetInterval(interval);
}
示例9: OnlyOneCopy
private static bool OnlyOneCopy()
{
bool isnew;
s_setup_mutex = new Mutex(true, SETUP_MUTEX_NAME, out isnew);
RestoreEvent = null;
try
{
#if RELEASE
RestoreEvent = AutoResetEvent.OpenExisting(EVENT_NAME);
RestoreEvent.Set();
return false;
}
catch (WaitHandleCannotBeOpenedException)
{
#endif
string user = Environment.UserDomainName + "\\" + Environment.UserName;
EventWaitHandleSecurity evh_sec = new EventWaitHandleSecurity();
EventWaitHandleAccessRule rule = new EventWaitHandleAccessRule(user,
EventWaitHandleRights.Synchronize | EventWaitHandleRights.Modify,
AccessControlType.Allow);
evh_sec.AddAccessRule(rule);
bool was_created;
RestoreEvent = new EventWaitHandle(false, EventResetMode.AutoReset,
EVENT_NAME, out was_created, evh_sec);
}
catch (Exception)
{
}
return true;
}
示例10: DebuggerStart
private void DebuggerStart(EventWaitHandle startWaitHandle, Func<ProcessInformation> processCreator, Action<ProcessInformation> callback, Action<Exception> errorCallback) {
try {
_debuggerThread = Thread.CurrentThread;
// Note: processCreator is responsible for creating the process in DEBUG mode.
// Note: If processCreator throws an exception after creating the
// process, we may end up in a state where we received debugging events
// without having "_processInformation" set. We need to be able to deal
// with that.
_processInformation = processCreator();
callback(_processInformation);
}
catch (Exception e) {
errorCallback(e);
return;
}
finally {
startWaitHandle.Set();
}
_running = true;
try {
DebuggerLoop();
}
finally {
_running = false;
}
}
示例11: Should_be_able_to_cancel_message_reception_upon_disposal
public void Should_be_able_to_cancel_message_reception_upon_disposal()
{
const string mmfName = "Local\\test";
var message = "not null";
var messageCancelled = new EventWaitHandle(false, EventResetMode.ManualReset, mmfName + "_MessageCancelled");
messageCancelled.Set();
var messageReceiver = new MemoryMappedFileMessageReceiver(mmfName);
var task = new Task(() => message = messageReceiver.ReceiveMessage(ReadString));
task.Start();
var isSet = true;
while (isSet)
isSet = messageCancelled.WaitOne(0);
messageReceiver.Dispose();
task.Wait();
message.ShouldBeNull();
}
示例12: Main
public static void Main(string[] args)
{
var dir = @"c:\tmp";
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
ewh = new EventWaitHandle(false, EventResetMode.ManualReset);
for (int i = 0; i <= 10; i++)
{
var t = new Thread(ThreadProc);
t.Start(i);
Console.WriteLine("Tread {0} started", i);
}
watcher = new FileSystemWatcher()
{
Path = dir,
IncludeSubdirectories = false,
EnableRaisingEvents = true,
};
watcher.Created += (sender, eventArgs) =>
{
ewh.Set();
};
Console.WriteLine("Press any key....");
Console.ReadLine();
}
示例13: ServerResponds
public void ServerResponds() {
using (var container = SetupMefContainer()) {
using (var server = container.GetExport<IServerProcessProxy>().Value) {
var waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);
var request = new IpcRequest {
RequestId = 5,
Protocol = IpcProtocols.Echo,
Data = new IpcStringData {
Text = "sdfsdsd"
}
};
IpcResponse response = null;
server.RunAsync(request, x => {
response = x;
waitHandle.Set();
});
Assert.IsTrue(waitHandle.WaitOne(TimeSpan.FromSeconds(5.0)), "Server did not respond within 5 seconds.");
Assert.AreEqual(5, response.RequestId);
Assert.AreEqual(IpcProtocols.Echo, response.Protocol);
Assert.IsNotNull(request.Data);
Assert.IsNotNull(response.Data);
Assert.AreEqual(request.Data.GetType(), typeof(IpcStringData));
Assert.AreEqual(response.Data.GetType(), typeof(IpcStringData));
Assert.AreEqual((request.Data as IpcStringData).Text, (response.Data as IpcStringData).Text);
}
}
}
示例14: AuthSignIn
void AuthSignIn()
{
EventWaitHandle wait = new EventWaitHandle(false, EventResetMode.ManualReset);
SlackSocketClient client = new SlackSocketClient(token);
client.OnHello += () =>
{
wait.Set();
};
client.Connect((l) =>
{
if (!l.ok) return;
BeginInvoke(new Action(() =>
{
connected = new ConnectedInterface(client, l);
connected.Dock = DockStyle.Fill;
Controls.Add(connected);
password.Visible = false;
}));
});
wait.WaitOne();
}
示例15: RunInThreadPoolWithEvents
static void RunInThreadPoolWithEvents()
{
double result = 0d;
// We use this event to signal when the thread is don executing.
EventWaitHandle calculationDone = new EventWaitHandle(false, EventResetMode.AutoReset);
// Create a work item to read from I/O
ThreadPool.QueueUserWorkItem((x) => {
result += Utils.CommonFunctions.ReadDataFromIO();
calculationDone.Set();
});
// Save the result of the calculation into another variable
double result2 = Utils.CommonFunctions.DoIntensiveCalculations();
// Wait for the thread to finish
calculationDone.WaitOne();
// Calculate the end result
result += result2;
// Print the result
Console.WriteLine("The result is {0}", result);
}