本文整理汇总了C#中System.Threading.AutoResetEvent.Close方法的典型用法代码示例。如果您正苦于以下问题:C# AutoResetEvent.Close方法的具体用法?C# AutoResetEvent.Close怎么用?C# AutoResetEvent.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.AutoResetEvent
的用法示例。
在下文中一共展示了AutoResetEvent.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAutoResetEvent
/// <summary>
/// Create an <see cref="AutoResetEvent"/> wrapper around the given native event.
/// </summary>
/// <param name="handle">The handle of the native event.</param>
/// <returns>An <see cref="AutoResetEvent"/> wrapping the given <paramref name="handle"/>.</returns>
public static AutoResetEvent GetAutoResetEvent( IntPtr handle )
{
AutoResetEvent ev = new AutoResetEvent( false );
ev.Close();
GC.ReRegisterForFinalize( ev );
ev.SafeWaitHandle = new Microsoft.Win32.SafeHandles.SafeWaitHandle( handle, false );
return ev;
}
示例2: ExecutePlugin
public override IPlugin ExecutePlugin()
{
ConfigItem.PluginRunContext = this;
if (Plugins.ContainsKey(ConfigItem.Url))
{
_init[ConfigItem.Url] = false;
IPlugin thePlugin = Plugins[ConfigItem.Url];
ProcessParametricPlugin(thePlugin);
thePlugin.InitPlugin(ConfigItem, Context);
thePlugin.ShowPlugin(ConfigItem, Context);
return Plugins[ConfigItem.Url];
}
else
{
AutoResetEvent theSignal = new AutoResetEvent(false);
ThreadRun runThread = new ThreadRun(ConfigItem, Context, theSignal, Plugins, this);
ThreadStart ts = new ThreadStart(runThread.Run);
Thread td = new Thread(ts);
td.SetApartmentState(ApartmentState.STA);
td.IsBackground = true;
td.Name = ConfigItem.Url;
td.Start();
_init[ConfigItem.Url] = true;
theSignal.WaitOne();
theSignal.Close();
return Plugins[ConfigItem.Url];
}
}
示例3: Download
public void Download(Uri url, string saveLoc)
{
try
{
using (ExtendedWebClient setupDownloader = new ExtendedWebClient())
{
setupDownloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(setupDownloader_DownloadProgressChanged);
setupDownloader.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(setupDownloader_DownloadFileCompleted);
setupDownloader.DownloadFileAsync(url, saveLoc);
Console.WriteLine("Downloading setup - ");
threadBlocker = new AutoResetEvent(false);
threadBlocker.WaitOne();
}
if (isSuccessful == false)
{
throw error;
}
}
finally
{
if (threadBlocker != null)
{
threadBlocker.Close();
threadBlocker = null;
}
}
}
示例4: BackgroundDispatcher
public BackgroundDispatcher(string name)
{
AutoResetEvent are = new AutoResetEvent(false);
Thread thread = new Thread((ThreadStart)delegate
{
_dispatcher = Dispatcher.CurrentDispatcher;
_dispatcher.UnhandledException +=
delegate(
object sender,
DispatcherUnhandledExceptionEventArgs e)
{
e.Handled = true;
};
are.Set();
Dispatcher.Run();
});
thread.Name = string.Format("BackgroundStaDispatcher({0})", name);
thread.SetApartmentState(ApartmentState.MTA);
thread.IsBackground = true;
thread.Start();
are.WaitOne();
are.Close();
are.Dispose();
}
示例5: Dispose
public void Dispose()
{
stopRequested = true;
stopWh = new AutoResetEvent(false);
wh.Set();
stopWh.WaitOne();
stopWh.Close();
wh.Close();
worker.Join();
}
示例6: SafeWaitHandle
[Test] // bug #81529
public void SafeWaitHandle ()
{
AutoResetEvent are1 = new AutoResetEvent (false);
AutoResetEvent are2 = new AutoResetEvent (false);
SafeWaitHandle swh1 = are1.SafeWaitHandle;
SafeWaitHandle swh2 = are2.SafeWaitHandle;
are1.SafeWaitHandle = are2.SafeWaitHandle;
Assert.AreSame (are1.SafeWaitHandle, are2.SafeWaitHandle, "#1");
Assert.AreEqual (are1.Handle, are2.Handle, "#2");
Assert.IsFalse (are1.SafeWaitHandle.IsInvalid, "#3");
Assert.IsFalse (are1.SafeWaitHandle.IsClosed, "#4");
Assert.IsFalse (swh1.IsClosed, "#5");
Assert.IsFalse (swh1.IsInvalid, "#6");
swh1.Dispose ();
are1.Close ();
}
示例7: Handle_Valid
public void Handle_Valid ()
{
AutoResetEvent are1 = new AutoResetEvent (false);
SafeWaitHandle swh1 = are1.SafeWaitHandle;
Assert.IsFalse (swh1.IsClosed, "#1");
Assert.IsFalse (swh1.IsInvalid, "#2");
IntPtr dummyHandle = (IntPtr) 2;
are1.Handle = dummyHandle;
Assert.AreEqual (are1.Handle, dummyHandle, "#3");
Assert.IsFalse (swh1.IsClosed, "#4");
Assert.IsFalse (swh1.IsClosed, "#5");
Assert.IsFalse (swh1.IsInvalid, "#6");
Assert.IsFalse (are1.SafeWaitHandle.IsClosed, "#7");
Assert.IsFalse (are1.SafeWaitHandle.IsInvalid, "#8");
are1.Close ();
swh1.Dispose ();
}
示例8: DownloadSetup
protected String DownloadSetup(String downloadLocation, String extn)
{
String tempLocationToSave = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + "." + extn);
try
{
using (WebClient setupDownloader = new WebClient())
{
setupDownloader.DownloadProgressChanged += new DownloadProgressChangedEventHandler(setupDownloader_DownloadProgressChanged);
setupDownloader.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(setupDownloader_DownloadFileCompleted);
setupDownloader.DownloadFileAsync(new Uri(downloadLocation), tempLocationToSave);
Console.Write("Downloading setup - ");
threadBlocker = new AutoResetEvent(false);
threadBlocker.WaitOne();
}
}
finally
{
if (threadBlocker != null) { threadBlocker.Close(); }
}
return tempLocationToSave;
}
示例9: Ping
private void Ping()
{
if (this.Device != null && this.Device.ID != 0)
{
try
{
AutoResetEvent waiter = new AutoResetEvent(false);
Ping pingSender = new Ping();
pingSender.PingCompleted += new PingCompletedEventHandler(PingCompletedCallback);
IPAddress address = IPAddress.Parse(this.Device.IP); ;
int timeout = 3000;
pingSender.SendAsync(address, timeout, waiter);
waiter.Close();
}
catch (Exception)
{
}
}
}
示例10: StartScheduler
public void StartScheduler(IMFClock pClock)
{
if (m_bSchedulerThread != false)
{
throw new COMException("Scheduler already started", E_Unexpected);
}
m_pClock = pClock;
// Set a high the timer resolution (ie, short timer period).
timeBeginPeriod(1);
// Create an event to wait for the thread to start.
m_hThreadReadyEvent = new AutoResetEvent(false);
try
{
// Use the c# threadpool to avoid creating a thread
// when streaming begins
ThreadPool.QueueUserWorkItem(new WaitCallback(SchedulerThreadProcPrivate));
m_hThreadReadyEvent.WaitOne(SCHEDULER_TIMEOUT, false);
m_bSchedulerThread = true;
}
finally
{
// Regardless success/failure, we are done using the "thread ready" event.
m_hThreadReadyEvent.Close();
m_hThreadReadyEvent = null;
}
}
示例11: RunPolling
private void RunPolling() {
IsPolling = true;
while (true) {
try {
waitHandle = new AutoResetEvent(false);
while (!stopRequested) {
OnPollingStarted();
FetchJobResults();
OnPollingFinished();
waitHandle.WaitOne(Interval);
}
waitHandle.Close();
IsPolling = false;
return;
}
catch (Exception e) {
OnExceptionOccured(e);
if (!autoResumeOnException) {
waitHandle.Close();
IsPolling = false;
return;
}
}
}
}
示例12: Handle_Invalid
[Test] // bug #81529
public void Handle_Invalid ()
{
AutoResetEvent are1 = new AutoResetEvent (false);
SafeWaitHandle swh1 = are1.SafeWaitHandle;
are1.Handle = (IntPtr) (-1);
Assert.IsTrue (swh1 != are1.SafeWaitHandle, "#1");
Assert.IsFalse (swh1.IsClosed, "#2");
Assert.IsFalse (swh1.IsInvalid, "#3");
Assert.IsFalse (are1.SafeWaitHandle.IsClosed, "#4");
Assert.IsTrue (are1.SafeWaitHandle.IsInvalid, "#5");
are1.Close ();
swh1.Dispose ();
}
示例13: StartWatcher
public void StartWatcher()
{
m_bRun = true;
var wh = new AutoResetEvent(false);
var fsw = new FileSystemWatcher(".");
fsw.Filter = m_logfileName;
fsw.Changed += (s, e) => wh.Set();
try
{
var fs = new FileStream(m_logfileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
fs.Seek(0, SeekOrigin.End);
using (var sr = new StreamReader(fs))
{
var s = "";
while (m_bRun == true)
{
s = sr.ReadLine();
if (s != null)
{
foreach (string search in searchLinesInclude)
{
if (s.Contains(search) && !searchLinesExclude.Any(s.Contains))
{
if (SendEmail(search, s))
{
m_processed++;
SetProcessed(Color.Blue, Color.White);
SetTitle(System.IO.Path.GetFileName(m_logfileName));
m_timer.Enabled = true;
}
break;
}
}
}
else
{
wh.WaitOne(1000);
}
}
}
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
SetStatus("Error processing file");
}
wh.Close();
m_finishedEvent.Set();
}
示例14: GetObjectName
private string GetObjectName(Primitive prim, int distance)
{
string name = "Loading...";
string ownerName = "Loading...";
if (prim.Properties == null)
{
//if (prim.ParentID != 0) throw new Exception("Requested properties for non root prim");
propRequester.RequestProps(prim.LocalID);
}
else
{
name = prim.Properties.Name;
// prim.Properties.GroupID is the actual group when group owned, not prim.GroupID
if (UUID.Zero == prim.Properties.OwnerID &&
PrimFlags.ObjectGroupOwned == (prim.Flags & PrimFlags.ObjectGroupOwned) &&
UUID.Zero != prim.Properties.GroupID)
{
System.Threading.AutoResetEvent nameReceivedSignal = new System.Threading.AutoResetEvent(false);
EventHandler<GroupNamesEventArgs> cbGroupName = new EventHandler<GroupNamesEventArgs>(
delegate(object sender, GroupNamesEventArgs e)
{
if (e.GroupNames.ContainsKey(prim.Properties.GroupID))
{
e.GroupNames.TryGetValue(prim.Properties.GroupID, out ownerName);
if (string.IsNullOrEmpty(ownerName))
ownerName = "Loading...";
if (null != nameReceivedSignal)
nameReceivedSignal.Set();
}
});
client.Groups.GroupNamesReply += cbGroupName;
client.Groups.RequestGroupName(prim.Properties.GroupID);
nameReceivedSignal.WaitOne(5000, false);
nameReceivedSignal.Close();
client.Groups.GroupNamesReply -= cbGroupName;
}
else
ownerName = instance.Names.Get(prim.Properties.OwnerID);
}
return String.Format("{0} ({1}m) owned by {2}", name, distance, ownerName);
}
示例15: WaitForDeploymentComplete
private void WaitForDeploymentComplete(string requestToken)
{
AutoResetEvent threadBlocker = null;
try
{
threadBlocker = new AutoResetEvent(false);
deployAppWaitTimer = new System.Timers.Timer(5000);
deployAppWaitTimer.Elapsed += new ElapsedEventHandler(
delegate(object sender, ElapsedEventArgs e)
{
string requestUri;
string responseXml;
bool isError;
HttpWebRequest webRequest;
HttpWebResponse webResponse = null;
try
{
Console.Write("Storage account creation status: ");
deployAppWaitTimer.Stop();
requestUri = string.Format("https://management.core.windows.net/{0}/operations/{1}", _subscriptionId, requestToken);
webRequest = (HttpWebRequest)WebRequest.Create(requestUri);
webRequest.Method = "GET";
webRequest.ClientCertificates.Add(_cert);
webRequest.Headers.Add("x-ms-version", "2009-10-01");
webResponse = (HttpWebResponse)webRequest.GetResponse();
if (webResponse.StatusCode != HttpStatusCode.OK)
{
throw new Exception(@"Error fetching status code for creating storage account. Error code - " +
webResponse.StatusCode.ToString() +
" Description - " + webResponse.StatusDescription);
}
using (Stream responseStream = webResponse.GetResponseStream())
using (StreamReader responseStreamReader = new StreamReader(responseStream))
{
responseXml = responseStreamReader.ReadToEnd();
if (IsDeploymentComplete(responseXml, out isError) == true)
{
Console.WriteLine("Successfull.");
deployAppWaitTimer.Dispose();
threadBlocker.Set();
}
else if (isError == true) //Give up.
{
Console.WriteLine("Failed.");
deployAppWaitTimer.Dispose();
threadBlocker.Set();
}
else
{
Console.WriteLine("In progress.");
deployAppWaitTimer.Start();
}
}
}
finally
{
if (webResponse != null) webResponse.Close();
}
});
deployAppWaitTimer.Start();
threadBlocker.WaitOne();
}
finally
{
if (threadBlocker != null) threadBlocker.Close();
}
}