Files
mirror-processhacker/trunk/ProcessHacker/Components/SemaphoreProperties.cs
T
wj32 2c3c8a402f added ability to detach processes from debuggers
git-svn-id: svn://svn.code.sf.net/p/processhacker/code@1376 21ef857c-d57f-4fe0-8362-d861dc6d29cd
2009-06-06 00:53:45 +00:00

63 lines
2.0 KiB
C#

using System;
using System.Windows.Forms;
using ProcessHacker.Common;
using ProcessHacker.Native.Api;
using ProcessHacker.Native.Objects;
using ProcessHacker.Native.Security;
namespace ProcessHacker.Components
{
public partial class SemaphoreProperties : UserControl
{
private SemaphoreHandle _semaphoreHandle;
private NativeHandle<SemaphoreAccess> _dupHandle;
public SemaphoreProperties(SemaphoreHandle semaphoreHandle)
{
InitializeComponent();
_semaphoreHandle = semaphoreHandle;
this.UpdateInfo();
}
private void UpdateInfo()
{
var basicInfo = _semaphoreHandle.GetBasicInformation();
labelCurrentCount.Text = basicInfo.CurrentCount.ToString();
labelMaximumCount.Text = basicInfo.MaximumCount.ToString();
}
private void buttonAcquire_Click(object sender, EventArgs e)
{
try
{
_dupHandle = _semaphoreHandle.Duplicate((SemaphoreAccess)StandardRights.Synchronize);
_semaphoreHandle = SemaphoreHandle.FromHandle(_dupHandle);
if (_semaphoreHandle.Wait(0) != NtStatus.Success)
throw new Exception("Could not acquire the semaphore.");
this.UpdateInfo();
}
catch (Exception ex)
{
PhUtils.ShowMessage(ex);
}
}
private void buttonRelease_Click(object sender, EventArgs e)
{
try
{
_dupHandle = _semaphoreHandle.Duplicate(SemaphoreAccess.QueryState | SemaphoreAccess.ModifyState);
_semaphoreHandle = SemaphoreHandle.FromHandle(_dupHandle);
_semaphoreHandle.Release();
this.UpdateInfo();
}
catch (Exception ex)
{
PhUtils.ShowMessage(ex);
}
}
}
}