本文整理汇总了C#中System.Threading.EventWaitHandle类的典型用法代码示例。如果您正苦于以下问题:C# EventWaitHandle类的具体用法?C# EventWaitHandle怎么用?C# EventWaitHandle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EventWaitHandle类属于System.Threading命名空间,在下文中一共展示了EventWaitHandle类的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: 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;
}
}
示例3: ActivateThreaded
/// <summary>
/// Turns this panel into multi-threaded mode.
/// This will sort of glitch out other gdi things on the system, but at least its fast...
/// </summary>
public void ActivateThreaded()
{
ewh = new EventWaitHandle(false, EventResetMode.AutoReset);
threadPaint = new Thread(PaintProc);
threadPaint.IsBackground = true;
threadPaint.Start();
}
示例4: ResponseListener
/// <summary>
/// ctor
/// </summary>
/// <param name="session"></param>
public ResponseListener(O2GSession session)
{
mRequestID = string.Empty;
mResponse = null;
mSyncResponseEvent = new EventWaitHandle(false, EventResetMode.AutoReset);
mSession = session;
}
示例5: 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();
}
示例6: HttpChannelListenerEntry
public HttpChannelListenerEntry (ChannelDispatcher channel, EventWaitHandle waitHandle)
{
ChannelDispatcher = channel;
WaitHandle = waitHandle;
ContextQueue = new Queue<HttpContextInfo> ();
RetrieverLock = new object ();
}
示例7: EndProfile
private void EndProfile(RequestItem pending, IRestResponse response, EventWaitHandle signal)
{
TimeSpan elapsed = pending.Elapsed;
network.Profile(response, pending.Started, elapsed);
network.ProfilePendingRemove(pending);
signal.Set();
}
示例8: FetchSchema
/// <summary>
/// Fetches the Tf2 Item schema.
/// </summary>
/// <param name="apiKey">The API key.</param>
/// <returns>A deserialized instance of the Item Schema.</returns>
/// <remarks>
/// The schema will be cached for future use if it is updated.
/// </remarks>
public static Schemazh FetchSchema()
{
var url = SchemaApiUrlBase;
// just let one thread/proc do the initial check/possible update.
bool wasCreated;
var mre = new EventWaitHandle(false,
EventResetMode.ManualReset, SchemaMutexName, out wasCreated);
// the thread that create the wait handle will be the one to
// write the cache file. The others will wait patiently.
if (!wasCreated)
{
bool signaled = mre.WaitOne(10000);
if (!signaled)
{
return null;
}
}
HttpWebResponse response = Drop.SteamWeb.Request(url, "GET");
DateTime schemaLastModified = DateTime.Parse(response.Headers["Last-Modified"]);
string result = GetSchemaString(response, schemaLastModified);
response.Close();
// were done here. let others read.
mre.Set();
SchemaResult schemaResult = JsonConvert.DeserializeObject<SchemaResult>(result);
return schemaResult.result ?? null;
}
示例9: IsFirstInstance
/// <summary>
/// Creates the single instance.
/// </summary>
/// <param name="name">The name.</param>
/// <returns></returns>
public static bool IsFirstInstance(string name)
{
EventWaitHandle eventWaitHandle = null;
string eventName = string.Format("{0}-{1}", Environment.MachineName, name);
var isFirstInstance = false;
try
{
// try opening existing wait handle
eventWaitHandle = EventWaitHandle.OpenExisting(eventName);
}
catch
{
// got exception = handle wasn't created yet
isFirstInstance = true;
}
if (isFirstInstance)
{
// init handle
eventWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName);
// register wait handle for this instance (process)
ThreadPool.RegisterWaitForSingleObject(eventWaitHandle, WaitOrTimerCallback, null, Timeout.Infinite, false);
eventWaitHandle.Close();
}
return isFirstInstance;
}
示例10: Start
public void Start(EventWaitHandle startEventHandle)
{
Contract.Requires<ArgumentNullException>(startEventHandle != null, "startEventHandle");
if (!Active)
{
var waitHandle = new ManualResetEventSlim(false);
lock (_listener)
{
_shuttingDown = false;
_listener.Start();
_acceptSocketThread = new Thread(AcceptSocketLoop);
_acceptSocketThread.Start(waitHandle);
}
waitHandle.Wait();
_logger.DebugFormat("started on {0}", LocalEndPoint);
}
startEventHandle.Set();
}
示例11: ResolveToString
public override string ResolveToString()
{
if (!Parameters.Contains("url") || string.IsNullOrEmpty(Parameters["url"].ToString()))
throw new InvalidOperationException();
string url = Parameters["url"].ToString();
string resultString = null;
using (var wc = new WebClient())
{
var tlock = new EventWaitHandle(false, EventResetMode.ManualReset);
wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler((sender, e) =>
{
// TODO: Add progress monitoring
});
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler((sender, e) =>
{
resultString = e.Result;
tlock.Set();
});
wc.DownloadStringAsync(new Uri(url));
tlock.WaitOne();
tlock.Dispose();
}
return resultString;
}
示例12: Message
/// <summary>
/// Constructor for a message with or without waiting mechanism
/// </summary>
/// <param name="action"></param>
/// <param name="waitForInvocation">When true, the message creator requires a waiting mechanism</param>
public Message(Action action, bool waitForInvocation)
{
this.m_action = action;
if (waitForInvocation) this.m_waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset);
else this.m_waitHandle = null;
}
示例13: CreateSingleInstance
public static bool CreateSingleInstance(string name, EventHandler<InstanceCallbackEventArgs> callback, string[] args)
{
string eventName = string.Format("{0}-{1}", Environment.MachineName, name);
InstanceProxy.IsFirstInstance = false;
InstanceProxy.CommandLineArgs = args;
try
{
using (EventWaitHandle eventWaitHandle = EventWaitHandle.OpenExisting(eventName))
{
UpdateRemoteObject(name);
if (eventWaitHandle != null) eventWaitHandle.Set();
}
Environment.Exit(0);
}
catch
{
InstanceProxy.IsFirstInstance = true;
using (EventWaitHandle eventWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName))
{
ThreadPool.RegisterWaitForSingleObject(eventWaitHandle, WaitOrTimerCallback, callback, Timeout.Infinite, false);
}
RegisterRemoteType(name);
}
return InstanceProxy.IsFirstInstance;
}
示例14: Installer
public Installer(string filename)
{
try {
MsiFilename = filename;
Task.Factory.StartNew(() => {
// was coapp just installed by the bootstrapper?
if (((AppDomain.CurrentDomain.GetData("COAPP_INSTALLED") as string) ?? "false").IsTrue()) {
// we'd better make sure that the most recent version of the service is running.
EngineServiceManager.InstallAndStartService();
}
InstallTask = LoadPackageDetails();
});
bool wasCreated;
var ewhSec = new EventWaitHandleSecurity();
ewhSec.AddAccessRule(new EventWaitHandleAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), EventWaitHandleRights.FullControl, AccessControlType.Allow));
_ping = new EventWaitHandle(false, EventResetMode.ManualReset, "BootstrapperPing", out wasCreated, ewhSec);
// if we got this far, CoApp must be running.
try {
Application.ResourceAssembly = Assembly.GetExecutingAssembly();
} catch {
}
_window = new InstallerMainWindow(this);
_window.ShowDialog();
if (Application.Current != null) {
Application.Current.Shutdown(0);
}
ExitQuick();
} catch (Exception e) {
DoError(InstallerFailureState.FailedToGetPackageDetails, e);
}
}
示例15: SharedMemoryListener
public SharedMemoryListener(IPCPeer peer)
{
_waitHandle = new EventWaitHandle(false, EventResetMode.ManualReset, EventName);
_exit = false;
_peer = peer;
_lastSyncedVersion = null;
}