本文整理汇总了C#中NetMQPoller.Run方法的典型用法代码示例。如果您正苦于以下问题:C# NetMQPoller.Run方法的具体用法?C# NetMQPoller.Run怎么用?C# NetMQPoller.Run使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetMQPoller
的用法示例。
在下文中一共展示了NetMQPoller.Run方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NetMQPoller
void IShimHandler.Run(PairSocket shim)
{
Poller = new NetMQPoller();
Shim = shim;
Shim.ReceiveReady += OnShimReady;
Poller.Add(Shim);
Initialize();
Shim.SignalOK();
Poller.Run();
Cleanup();
}
示例2: TwoMessagesFromRouterToDealer
public void TwoMessagesFromRouterToDealer()
{
using (var server = new RouterSocket())
using (var client = new DealerSocket())
using (var poller = new NetMQPoller { client })
{
var port = server.BindRandomPort("tcp://*");
client.Connect("tcp://127.0.0.1:" + port);
var cnt = 0;
client.ReceiveReady += (sender, e) =>
{
var strs = e.Socket.ReceiveMultipartStrings();
foreach (var str in strs)
{
Console.WriteLine(str);
}
cnt++;
if (cnt == 2)
{
poller.Stop();
}
};
byte[] clientId = Encoding.Unicode.GetBytes("ClientId");
client.Options.Identity = clientId;
const string request = "GET /\r\n";
const string response = "HTTP/1.0 200 OK\r\n" +
"Content-Type: text/plain\r\n" +
"\r\n" +
"Hello, World!";
client.SendFrame(request);
byte[] serverId = server.ReceiveFrameBytes();
Assert.AreEqual(request, server.ReceiveFrameString());
// two messages in a row, not frames
server.SendMoreFrame(serverId).SendFrame(response);
server.SendMoreFrame(serverId).SendFrame(response);
poller.Run();
}
}
示例3: RunActor
/// <summary>
/// This method is being run asynchronously by m_actor.
/// </summary>
/// <param name="shim"></param>
private void RunActor(PairSocket shim)
{
_pipe = shim;
_pipe.ReceiveReady += OnPipeReceiveReady;
var reapTimer = new NetMQTimer(TimeSpan.FromMilliseconds(1000));
reapTimer.Elapsed += OnReapTimerElapsed;
// Start poller, but poll only the _pipe. Start() and Stop() will add/remove other items to poll
_poller = new NetMQPoller { _pipe, reapTimer };
// Signal the actor that we're ready to work
_pipe.SignalOK();
// polling until cancelled
_poller.Run();
reapTimer.Enable = false;
reapTimer.Elapsed -= OnReapTimerElapsed;
}
示例4: TestPollerDispose
public void TestPollerDispose()
{
const int timerIntervalMillis = 10;
var timer = new NetMQTimer(TimeSpan.FromMilliseconds(timerIntervalMillis));
var signal = new ManualResetEvent(false);
var count = 0;
timer.Elapsed += (s, a) =>
{
if (count++ == 5)
signal.Set();
};
NetMQPoller poller;
using (poller = new NetMQPoller { timer })
{
poller.RunAsync();
Assert.IsTrue(signal.WaitOne(500));
Assert.IsTrue(poller.IsRunning);
Assert.Throws<InvalidOperationException>(() => poller.Run());
}
Assert.IsFalse(poller.IsRunning);
Assert.Throws<ObjectDisposedException>(() => poller.Run());
Assert.Throws<ObjectDisposedException>(() => poller.Stop());
Assert.Throws<ObjectDisposedException>(() => poller.Add(timer));
Assert.Throws<ObjectDisposedException>(() => poller.Remove(timer));
}