本文整理汇总了C#中System.Threading.ManualResetEvent.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# ManualResetEvent.Dispose方法的具体用法?C# ManualResetEvent.Dispose怎么用?C# ManualResetEvent.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.ManualResetEvent
的用法示例。
在下文中一共展示了ManualResetEvent.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Socket_ConnectAsyncDnsEndPoint_Success
public void Socket_ConnectAsyncDnsEndPoint_Success()
{
Assert.True(Capability.IPv4Support());
int port;
SocketTestServer server = SocketTestServer.SocketTestServerFactory(IPAddress.Loopback, out port);
SocketAsyncEventArgs args = new SocketAsyncEventArgs();
args.RemoteEndPoint = new DnsEndPoint("localhost", port);
args.Completed += OnConnectAsyncCompleted;
ManualResetEvent complete = new ManualResetEvent(false);
args.UserToken = complete;
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Assert.True(sock.ConnectAsync(args));
complete.WaitOne();
Assert.Equal(SocketError.Success, args.SocketError);
Assert.Null(args.ConnectByNameError);
complete.Dispose();
sock.Dispose();
server.Dispose();
}
示例2: WaitOneNonAlertable_disposed_error
public void WaitOneNonAlertable_disposed_error()
{
var e = new ManualResetEvent(true);
e.Dispose();
e.WaitOneNonAlertable(10);
}
示例3: StartsElectionAfterElectionTimeout
public void StartsElectionAfterElectionTimeout()
{
// arrange
var resetEvent = new ManualResetEvent(false);
var timeout = TimeSpan.FromMilliseconds(100);
var configMock = new Mock<IServerConfiguration>();
configMock.Setup(mocked => mocked.ElectionTimeout).Returns(timeout);
var config = configMock.Object;
var scheduler = new EventLoop();
var serverMock = new Mock<IConsensusServerStateApi>();
serverMock.Setup(mocked => mocked.StartElection()).Callback(() => resetEvent.Set());
serverMock.Setup(mocked => mocked.Configuration).Returns(config);
serverMock.Setup(mocked => mocked.Scheduler).Returns(scheduler);
var server = serverMock.Object;
var state = new Follower(server);
// act
state.Start();
var changedToCandidate = resetEvent.WaitOne(timeout + timeout);
// assert
Assert.That(changedToCandidate, Is.True, "An election timout should have occurred and the state should be changed to candidate");
// cleanup
scheduler.Dispose();
resetEvent.Dispose();
}
示例4: DispatcherThread
public DispatcherThread()
{
startedEvent = new ManualResetEvent(false);
thread = new Thread(Run);
thread.SetApartmentState(ApartmentState.STA);
thread.Name = "DispatcherThread";
thread.Start();
startedEvent.WaitOne();
startedEvent.Dispose();
startedEvent = null;
}
示例5: Socket_ConnectAsyncUnixDomainSocketEndPoint_Success
public void Socket_ConnectAsyncUnixDomainSocketEndPoint_Success()
{
string path = null;
SocketTestServer server = null;
UnixDomainSocketEndPoint endPoint = null;
for (int attempt = 0; attempt < 5; attempt++)
{
path = GetRandomNonExistingFilePath();
endPoint = new UnixDomainSocketEndPoint(path);
try
{
server = SocketTestServer.SocketTestServerFactory(endPoint, ProtocolType.Unspecified);
break;
}
catch (SocketException)
{
// Path selection is contingent on a successful Bind().
// If it fails, the next iteration will try another path.
}
}
try
{
Assert.NotNull(server);
SocketAsyncEventArgs args = new SocketAsyncEventArgs();
args.RemoteEndPoint = endPoint;
args.Completed += OnConnectAsyncCompleted;
ManualResetEvent complete = new ManualResetEvent(false);
args.UserToken = complete;
Socket sock = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
Assert.True(sock.ConnectAsync(args));
complete.WaitOne();
Assert.Equal(SocketError.Success, args.SocketError);
Assert.Null(args.ConnectByNameError);
complete.Dispose();
sock.Dispose();
server.Dispose();
}
finally
{
File.Delete(path);
}
}
示例6: ProcessesCallbacks
public void ProcessesCallbacks()
{
// arrange
var worker = new EventLoopWorker();
var workDone = new ManualResetEvent(false);
workDone.Reset();
// act
worker.Schedule(() => workDone.Set());
// assert
Assert.That(workDone.WaitOne(TimeSpan.FromMilliseconds(100)), Is.True, "Exepcted work to be done within 100ms");
// dispose stuff
worker.Dispose();
workDone.Dispose();
}
示例7: Action
public override bool Action(string action)
{
bool result = base.Action(action);
if (result && action == ACTION_FILTER)
{
using (LogPurgerForm dlg = new LogPurgerForm())
{
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
using (Utils.FrameworkDataUpdater upd = new Utils.FrameworkDataUpdater(Core))
{
_actionReady = new ManualResetEvent(false);
Thread thrd = new Thread(new ThreadStart(this.purgeLogsWithFilterThreadMethod));
thrd.Start();
while (!_actionReady.WaitOne(10))
{
System.Windows.Forms.Application.DoEvents();
}
thrd.Join();
_actionReady.Dispose();
_actionReady = null;
}
}
}
}
else if (result && action == ACTION_QUICKPURGE)
{
using (Utils.FrameworkDataUpdater upd = new Utils.FrameworkDataUpdater(Core))
{
_actionReady = new ManualResetEvent(false);
Thread thrd = new Thread(new ThreadStart(this.purgeLogsThreadMethod));
thrd.Start();
while (!_actionReady.WaitOne(10))
{
System.Windows.Forms.Application.DoEvents();
}
thrd.Join();
_actionReady.Dispose();
_actionReady = null;
}
}
return result;
}
示例8: SetIntervalCancel
public void SetIntervalCancel()
{
// arrange
var loop = new EventLoop();
loop.Start(() => { });
var callbackinvoked = new ManualResetEvent(false);
var callback = new Action(() => callbackinvoked.Set());
var timeout = TimeSpan.FromMilliseconds(100);
// act
var timer = loop.SetInterval(callback, timeout);
timer.Cancel();
// assert
Assert.That(callbackinvoked.WaitOne(timeout + timeout), Is.False);
// cleanup
loop.Dispose();
callbackinvoked.Dispose();
}
示例9: FromCommandLineArgsRaceCondition
public void FromCommandLineArgsRaceCondition() {
// https://pytools.codeplex.com/workitem/1429
var mre = new ManualResetEvent(false);
var tasks = new Task<bool>[100];
try {
for (int i = 0; i < tasks.Length; i += 1) {
tasks[i] = Task.Run(() => {
mre.WaitOne();
using (var arg = VisualStudioProxy.FromProcessId(123)) {
return arg is VisualStudioProxy;
}
});
}
mre.Set();
Assert.IsTrue(Task.WaitAll(tasks, TimeSpan.FromSeconds(30.0)));
Assert.IsTrue(tasks.All(t => t.Result));
} finally {
mre.Dispose();
Task.WaitAll(tasks, TimeSpan.FromSeconds(30.0));
}
}
示例10: AcceptServerTransport
internal static TransportBase AcceptServerTransport(TransportSettings settings)
{
ManualResetEvent complete = new ManualResetEvent(false);
int closed = 0;
TransportBase transport = null;
Action<TransportListener, TransportAsyncCallbackArgs> onTransport = (l, a) =>
{
if (a.Exception != null)
{
Debug.WriteLine(a.Exception.Message);
}
else
{
Debug.WriteLine("Listener accepted a transport.");
transport = a.Transport;
}
if (Interlocked.Exchange(ref closed, 1) == 0)
{
complete.Set();
}
};
TransportListener listener = settings.CreateListener();
Debug.WriteLine("Listeners are waiting for connections...");
listener.Listen(onTransport);
complete.WaitOne();
complete.Dispose();
transport.Closed += (s, a) =>
{
listener.Close();
Debug.WriteLine("Listeners Closed.");
};
return transport;
}
示例11: WaitWhileLocked
/// <summary>
/// Подождать пока объект не освободится
/// </summary>
/// <param name="actionKey">Уникальный ключ операции</param>
public static void WaitWhileLocked(string actionKey)
{
var waitWhileNotUnlocked = new ManualResetEvent(true);
lock (_lockerLock)
{
if (_lockedObjects.Contains(actionKey))
{
if (!_waitingThreads.ContainsKey(actionKey))
{
_waitingThreads.Add(actionKey, new List<ManualResetEvent>());
}
_waitingThreads[actionKey].Add(waitWhileNotUnlocked);
waitWhileNotUnlocked.Reset();
}
else
{
waitWhileNotUnlocked.Set();
}
}
waitWhileNotUnlocked.WaitOne();
waitWhileNotUnlocked.Dispose();
}
示例12: Socket_ConnectAsyncDnsEndPoint_HostNotFound
public void Socket_ConnectAsyncDnsEndPoint_HostNotFound()
{
Assert.True(Capability.IPv4Support());
SocketAsyncEventArgs args = new SocketAsyncEventArgs();
args.RemoteEndPoint = new DnsEndPoint("notahostname.invalid.corp.microsoft.com", UnusedPort);
args.Completed += OnConnectAsyncCompleted;
ManualResetEvent complete = new ManualResetEvent(false);
args.UserToken = complete;
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
bool willRaiseEvent = sock.ConnectAsync(args);
if (willRaiseEvent)
{
complete.WaitOne();
}
AssertHostNotFoundOrNoData(args);
complete.Dispose();
sock.Dispose();
}
示例13: AwaitUpdater
/// <summary>
///
/// </summary>
/// <param name="usercontrol"></param>
/// <returns>false if the user skipped.</returns>
public Task<bool> AwaitUpdater(UserControl usercontrol, IProductUpdate productUpdate)
{
var updateSkeletonControl = usercontrol as Updating.Userinterface.UpdateSkeletonControl;
if(updateSkeletonControl == null)
throw new InvalidCastException("Control is not an UpdateSkeletonControl");
if(updateSkeletonControl.DataContext == null)
throw new NullReferenceException("Datacontext of UpdateSkeletonControl not set");
var updatePropopsalViewModel = updateSkeletonControl.DataContext as UpdatePropopsalViewModel;
if(updatePropopsalViewModel == null)
throw new InvalidCastException("Datacontext of UpdateSkeletonControl is not of type UpdateProposalViewModel");
var manualResetEvent = new ManualResetEvent(false);
updatePropopsalViewModel.ViewModelInteraction.CloseWindow = () => manualResetEvent.Set();
var awaiterTask = new Task<bool>(() =>
{
// Wait for the async task to complete.
manualResetEvent.WaitOne();
// Dispose the manual reset event.
manualResetEvent.Dispose();
// Determine if we should close.
return productUpdate.IsManadatory;
});
awaiterTask.Start();
return awaiterTask;
}
示例14: Socket_ConnectAsyncDnsEndPoint_Success
public void Socket_ConnectAsyncDnsEndPoint_Success(SocketImplementationType type)
{
Assert.True(Capability.IPv4Support());
int port;
SocketTestServer server = SocketTestServer.SocketTestServerFactory(type, IPAddress.Loopback, out port);
SocketAsyncEventArgs args = new SocketAsyncEventArgs();
args.RemoteEndPoint = new DnsEndPoint("localhost", port);
args.Completed += OnConnectAsyncCompleted;
ManualResetEvent complete = new ManualResetEvent(false);
args.UserToken = complete;
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
bool willRaiseEvent = sock.ConnectAsync(args);
if (willRaiseEvent)
{
Assert.True(complete.WaitOne(TestSettings.PassingTestTimeout), "Timed out while waiting for connection");
}
Assert.Equal(SocketError.Success, args.SocketError);
Assert.Null(args.ConnectByNameError);
complete.Dispose();
sock.Dispose();
server.Dispose();
}
示例15: Stop
/// <summary>
/// Allows to stop the adapter.
///
/// Before returning, and if it is so configured,
/// the adapter sends a "suspend" request to
/// all the currently registred fixtures.
/// </summary>
public void Stop()
{
_logger.InfoFormat("Adapter is stopping");
try
{
if (_trigger != null)
{
var wait_handler = new ManualResetEvent(false);
_trigger.Dispose(wait_handler);
wait_handler.WaitOne();
wait_handler.Dispose();
_trigger = null;
_fixtureManager.Dispose();
}
if (PlatformConnector != null)
PlatformConnector.Dispose();
UDAPIService.Disconnect();
}
catch (Exception e)
{
_logger.Error("An error occured while disposing the adapter", e);
}
_stats.SetValue(AdapterCoreKeys.ADAPTER_STARTED, "0");
_logger.InfoFormat("Adapter stopped");
}