本文整理汇总了C#中System.Threading.AutoResetEvent类的典型用法代码示例。如果您正苦于以下问题:C# System.Threading.AutoResetEvent类的具体用法?C# System.Threading.AutoResetEvent怎么用?C# System.Threading.AutoResetEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
System.Threading.AutoResetEvent类属于命名空间,在下文中一共展示了System.Threading.AutoResetEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_be_able_to_configure_EasyNetQ_to_allow_message_with_a_blank_type_field
public void Should_be_able_to_configure_EasyNetQ_to_allow_message_with_a_blank_type_field()
{
var are = new System.Threading.AutoResetEvent(false);
var validation = new NullMessageValidator();
var bus = RabbitHutch.CreateBus("host=localhost", r =>
r.Register<IMessageValidationStrategy>(x => validation));
bus.Subscribe<MyMessage>("null_validation_test", message =>
{
Console.Out.WriteLine("Got message: {0}", message.Text);
are.Set();
});
// now use the basic client API to publish some JSON to the message type exchange ...
var factory = new RabbitMQ.Client.ConnectionFactory
{
HostName = "localhost"
};
using (var connection = factory.CreateConnection())
using (var channel = connection.CreateModel())
{
const string exchange = "EasyNetQ_Tests_MyMessage:EasyNetQ_Tests";
const string routingKey = "#";
const string bodyString = "{ Text: \"Hello from Mr Raw :)\" }";
var body = System.Text.Encoding.UTF8.GetBytes(bodyString);
var properties = channel.CreateBasicProperties();
channel.BasicPublish(exchange, routingKey, properties, body);
}
are.WaitOne(1000);
}
示例2: Run
public static void Run(string[] args)
{
if (args.Length == 0)
{
Command.Application application = new Command.Application();
IDisposable telnet = Parser.Listen(application, "telnet://:23");
IDisposable tcp = Parser.Listen(application, "tcp://:20");
IDisposable console = Parser.Listen(application, "console:///");
}
else
{
Application application = new Application();
Settings.Module settings = new Settings.Module()
{
//Header = "<link href=\"resources/settings.css\" rel=\"stylesheet\" type=\"text/css\"/>\n <link href=\"resources/settings.css\" rel=\"stylesheet\" type=\"text/css\"/>",
};
settings.Load("loader", new Loader(settings));
settings.Load("old.object", new Object());
settings.Load("application", new Command.Application());
application.Load(settings);
application.Start();
System.Threading.AutoResetEvent wait = new System.Threading.AutoResetEvent(false);
application.OnClosed += () => wait.Set();
wait.WaitOne();
//application.Execute();
}
}
示例3: Main
static void Main(string[] args)
{
// args:
// 0: jid, name
// 1: passwd
// 2: mcu jid
// 3: cmd
// 4: cmd_options
if (args.Length == 5)
{
string xmpp_domain = Environment.GetEnvironmentVariable("xmpp_domain");
if (xmpp_domain == null)
xmpp_domain = "app.zonekey.com.cn";
cs_zkrobot.client.NormalUser user = cs_zkrobot.client.UserFactory.makeNormal();
if (!user.login(args[0] + "@" + xmpp_domain, args[1]))
{
System.Console.WriteLine("login err: " + args[0] + "@" + xmpp_domain);
}
else
{
System.Console.WriteLine("req: to:" + args[2] + ", cmd=" + args[3] + ", options=" + args[4]);
System.Threading.AutoResetEvent comp_evt = new System.Threading.AutoResetEvent(false);
user.async_request(args[2] + "@" + xmpp_domain, args[3], args[4], cb_response, comp_evt);
comp_evt.WaitOne();
user.logout();
}
}
}
示例4: ServerLoopTimer
public ServerLoopTimer(float period)
{
_timer = new Timer(period);
_timer.Elapsed += () => { Set(); };
_are = new AutoResetEvent(true);
_timer.Enabled = true;
}
示例5: DeviceLocator_Notifications_DoesNotRaiseDeviceAvailableIfDisposed
public void DeviceLocator_Notifications_DoesNotRaiseDeviceAvailableIfDisposed()
{
var server = new MockCommsServer();
var deviceLocator = new MockDeviceLocator(server);
DiscoveredSsdpDevice device = null;
bool newlyDiscovered = false;
var receivedNotification = false;
using (var eventSignal = new System.Threading.AutoResetEvent(false))
{
deviceLocator.DeviceAvailable += (sender, args) =>
{
device = args.DiscoveredDevice;
newlyDiscovered = args.IsNewlyDiscovered;
receivedNotification = true;
};
deviceLocator.StartListeningForNotifications();
server.MockReceiveBroadcast(GetMockAliveNotification());
server.Dispose();
eventSignal.WaitOne(1000);
}
Assert.IsFalse(receivedNotification);
}
示例6: Test
public void Test()
{
System.Threading.AutoResetEvent evt = new System.Threading.AutoResetEvent(false);
Packets.LicensePlatePacket p = null;
int count = 0;
Manager mnger = new Manager(new PacketSplitter());
var parser = new Parsers.LicensePlateParser();
parser.Handler += licensePlate =>
{
System.Diagnostics.Debug.WriteLine(licensePlate.LicensePlate.LicenseNumber);
p = licensePlate;
++count;
if (count > 1000)
{
evt.Set();
}
};
mnger.Parsers.Add(parser);
mnger.Start();
evt.WaitOne(10000);
mnger.Stop();
Assert.IsNotNull(p);
}
示例7: PubSubTest
public void PubSubTest()
{
UdpBus bus = (UdpBus)Reflector.GetField(this.pool, "bus");
object received = null;
System.Threading.AutoResetEvent evt = new System.Threading.AutoResetEvent(false);
this.pool.Start();
HostConfiguration hostSpec = new HostConfiguration(0){ CameraID = 2, Name = "mike", };
bus.Publish(Topics.HostReply, hostSpec, 3000);
System.Threading.Thread.Sleep(6000);
var host = this.pool[hostSpec.StationID];
Assert.IsNotNull(host);
Assert.AreEqual("mike", host.Config.Name);
hostSpec.Name = "jack";
bus.Publish(Topics.HostReply, hostSpec, 3000);
System.Threading.Thread.Sleep(6000);
host = this.pool[hostSpec.StationID];
Assert.AreEqual("jack", host.Config.Name);
}
示例8: flushGraphics
/// </summary>
/// <param name="rect"></param>
internal void flushGraphics(Rectangle rect)
{
using (System.Threading.AutoResetEvent are = new System.Threading.AutoResetEvent(false))
{
SilverlightImplementation.dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
IList<AsyncOp> tmp = renderingOperations;
renderingOperations = pendingRenderingOperations;
pendingRenderingOperations = tmp;
if (rect == null)
{
_screen.Invalidate();
}
else
{
_graphics.clip = rect;
_graphics.destination.setClip(rect);
_screen.Invalidate();
}
_graphics.destination.setAlpha(255);
_graphics.destination.setColor(0);
are.Set();
}).AsTask().GetAwaiter().GetResult();
are.WaitOne();
}
}
示例9: CapsQueueRunning
public bool CapsQueueRunning()
{
if (Client.Network.CurrentSim.Caps.IsEventQueueRunning)
return true;
bool Success = false;
// make sure caps event queue is running
System.Threading.AutoResetEvent waitforCAPS = new System.Threading.AutoResetEvent(false);
EventHandler<EventQueueRunningEventArgs> capsRunning = delegate(object sender, EventQueueRunningEventArgs e)
{
waitforCAPS.Set();
};
Client.Network.EventQueueRunning += capsRunning;
if (waitforCAPS.WaitOne(10000, false))
{
Success = true;
}
else
{
Success = false;
Assert.Fail("Timeout waiting for event Queue to startup");
}
Client.Network.EventQueueRunning -= capsRunning;
return Success;
}
示例10: Restart
/// <summary>
/// Restart plex, wait for the specified delay between stop and start
/// </summary>
/// <param name="msDelay">The amount of time in ms to wait before starting after stop</param>
internal void Restart(int delay)
{
Stop();
State = PlexState.Pending;
System.Threading.AutoResetEvent autoEvent = new System.Threading.AutoResetEvent(false);
System.Threading.Timer t = new System.Threading.Timer((x) => { Start(); autoEvent.Set(); }, null, delay, System.Threading.Timeout.Infinite);
autoEvent.WaitOne();
t.Dispose();
}
示例11: OpenPythonConsole
public static PythonConsoleHost OpenPythonConsole(System.Windows.Forms.Form mainForm)
{
// ipy -D -X:TabCompletion -X:ColorfulConsole
if (m_pythonConsoleHost == null)
{
m_pythonConsoleHost = new PythonConsoleHost();
//System.Threading.ManualResetEvent eve = new System.Threading.ManualResetEvent(false);
dispatcher = mainForm;
System.Threading.AutoResetEvent are = new System.Threading.AutoResetEvent(false);
System.Threading.Thread _debugThread = new System.Threading.Thread(() =>
{
int r = AllocConsole();
if (r == 0)
{
throw new InvalidOperationException("Can't AllocConsole!");
}
StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput());
standardOutput.AutoFlush = true;
Console.SetOut(standardOutput);
//host.Options.RunAction = Microsoft.Scripting.Hosting.Shell.ConsoleHostOptions.Action.RunConsole;
m_pythonConsoleHost.Run(new string[] { "-X:ColorfulConsole", "-X:Debug", "-X:TabCompletion", "-X:ExceptionDetail", "-X:ShowClrExceptions" }); //
//are.Set();
m_pythonConsoleHost.Runtime.IO.RedirectToConsole();
IronPython.Runtime.ClrModule.SetCommandDispatcher(IronPython.Runtime.DefaultContext.Default, null);
r = FreeConsole();
if (r == 0)
{
throw new InvalidOperationException("Can't FreeConsole!");
}
m_pythonConsoleHost = null;
});
_debugThread.IsBackground = true;
_debugThread.SetApartmentState(System.Threading.ApartmentState.STA);
_debugThread.Start();
// Don't establish the alternative input execution behavior until the other thread is ready. Note, 'are' starts out unsignalled.
//are.WaitOne();
while (m_pythonConsoleHost.ScriptScope == null)
{
System.Threading.Thread.Sleep(1000);
}
IronPython.Runtime.ClrModule.SetCommandDispatcher(IronPython.Runtime.DefaultContext.Default, DispatchConsoleCommand);
}
return m_pythonConsoleHost;
}
示例12: GivenIHaveAServer
public void GivenIHaveAServer()
{
var wait = new System.Threading.AutoResetEvent(false);
var server = ScenarioContext.Current.Get<System.ServiceModel.ServiceHost>();
server.Opened += (sender, args) => wait.Set();
server.Open();
Assert.IsTrue(wait.WaitOne(TimeSpan.FromSeconds(1)));
}
示例13: GlibSync
// Sync up with the GLib thread. Should be called after the
// name, role, or parent are changed in UiaAtkBridge when
// checking for events, since we defer to an idle
// handler to call atk to avoid deadlock when atk
// emits signals. Called by RunInGuiThread in
// UiaAtkBridge.
public static void GlibSync ()
{
System.Threading.AutoResetEvent sync = new System.Threading.AutoResetEvent (false);
GLib.Timeout.Add (0, new GLib.TimeoutHandler (delegate {
sync.Set ();
return false;
}));
sync.WaitOne ();
sync.Close ();
}
示例14: Control
public Control(string ServerAddress, int Port, ref CarverLab.Utility.Logger logger)
{
log = logger;
m_sServerAddress = ServerAddress;
m_iPort = Port;
m_TCPClient = new System.Net.Sockets.TcpClient();
m_EventChannelConnectionComplete = new System.Threading.ManualResetEvent(false);
m_sLastError = "";
m_EventReceivedFile = new System.Threading.AutoResetEvent(false);
}
示例15: Execute
/// <summary>
/// Exectute the command
/// </summary>
/// <param name="args"></param>
/// <param name="fromAgentID"></param>
/// <returns></returns>
public override string Execute(string[] args, UUID fromAgentID)
{
if (args.Length < 1)
{
return "Usage: viewnote [notecard asset uuid]";
}
UUID note;
if (!UUID.TryParse(args[0], out note))
{
return "First argument expected agent UUID.";
}
System.Threading.AutoResetEvent waitEvent = new System.Threading.AutoResetEvent(false);
System.Text.StringBuilder result = new System.Text.StringBuilder();
// define a delegate to handle the reply
AssetManager.AssetReceivedCallback del = delegate(AssetDownload transfer, Asset asset)
{
if (transfer.Success)
{
result.AppendFormat("Raw Notecard Data: " + System.Environment.NewLine + " {0}", Utils.BytesToString(asset.AssetData));
waitEvent.Set();
}
};
// verify asset is loaded in store
if (Client.Inventory.Store.Contains(note))
{
// retrieve asset from store
InventoryItem ii = (InventoryItem)Client.Inventory.Store[note];
// subscribe to reply event
Client.Assets.OnAssetReceived += del;
// make request for asset
Client.Assets.RequestInventoryAsset(ii, true);
// wait for reply or timeout
if (!waitEvent.WaitOne(10000, false))
{
result.Append("Timeout waiting for notecard to download.");
}
// unsubscribe from reply event
Client.Assets.OnAssetReceived -= del;
}
else
{
result.Append("Cannot find asset in inventory store, use 'i' to populate store");
}
// return results
return result.ToString();
}