本文整理汇总了C#中Microsoft.AspNet.SignalR.Hosting.Memory.MemoryHost.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryHost.Dispose方法的具体用法?C# MemoryHost.Dispose怎么用?C# MemoryHost.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.AspNet.SignalR.Hosting.Memory.MemoryHost
的用法示例。
在下文中一共展示了MemoryHost.Dispose方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ManyUniqueGroups
public static IDisposable ManyUniqueGroups(int concurrency)
{
var host = new MemoryHost();
var threads = new List<Thread>();
var cancellationTokenSource = new CancellationTokenSource();
host.MapHubs();
for (int i = 0; i < concurrency; i++)
{
var thread = new Thread(_ =>
{
while (!cancellationTokenSource.IsCancellationRequested)
{
RunOne(host);
}
});
threads.Add(thread);
thread.Start();
}
return new DisposableAction(() =>
{
cancellationTokenSource.Cancel();
threads.ForEach(t => t.Join());
host.Dispose();
});
}
示例2: Run
public static IDisposable Run(int connections, int senders, string payload, string transport)
{
var host = new MemoryHost();
host.Configure(app =>
{
app.MapConnection<StressConnection>("/echo");
});
var countDown = new CountdownEvent(senders);
var cancellationTokenSource = new CancellationTokenSource();
for (int i = 0; i < connections; i++)
{
if (transport.Equals("longPolling", StringComparison.OrdinalIgnoreCase))
{
ThreadPool.QueueUserWorkItem(state =>
{
string connectionId = state.ToString();
LongPollingLoop(host, connectionId);
}, i);
}
else
{
string connectionId = i.ToString();
ProcessRequest(host, transport, connectionId);
}
}
for (var i = 0; i < senders; i++)
{
ThreadPool.QueueUserWorkItem(_ =>
{
while (!cancellationTokenSource.IsCancellationRequested)
{
string connectionId = i.ToString();
ProcessSendRequest(host, transport, connectionId, payload);
}
countDown.Signal();
});
}
return new DisposableAction(() =>
{
cancellationTokenSource.Cancel();
// Wait for all senders to stop
countDown.Wait(TimeSpan.FromMilliseconds(1000 * senders));
host.Dispose();
});
}
示例3: StressGroups
public static void StressGroups()
{
var host = new MemoryHost();
host.HubPipeline.EnableAutoRejoiningGroups();
host.MapHubs();
int max = 15;
var countDown = new CountDown(max);
var list = Enumerable.Range(0, max).ToList();
var connection = new Client.Hubs.HubConnection("http://foo");
var proxy = connection.CreateHubProxy("MultGroupHub");
var bus = (MessageBus)host.DependencyResolver.Resolve<IMessageBus>();
proxy.On<int>("Do", i =>
{
lock (list)
{
if (!list.Remove(i))
{
Debugger.Break();
}
}
countDown.Dec();
});
try
{
connection.Start(host).Wait();
for (int i = 0; i < max; i++)
{
proxy.Invoke("Do", i).Wait();
}
int retry = 3;
bool result = false;
do
{
result = countDown.Wait(TimeSpan.FromSeconds(10));
if (!result)
{
Console.WriteLine("Didn't receive " + max + " messages. Got " + (max - countDown.Count) + " missed (" + String.Join(",", list.Select(i => i.ToString())) + ")");
Console.WriteLine("A=" + bus.AllocatedWorkers + " B=" + bus.BusyWorkers);
countDown.Reset();
}
retry--;
} while (retry > 0);
if (!result)
{
Console.WriteLine("A=" + bus.AllocatedWorkers + " B=" + bus.BusyWorkers);
Debugger.Break();
}
}
finally
{
connection.Stop();
host.Dispose();
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
示例4: BrodcastFromServer
public static IDisposable BrodcastFromServer()
{
var host = new MemoryHost();
IHubContext context = null;
host.Configure(app =>
{
var config = new HubConfiguration()
{
Resolver = new DefaultDependencyResolver()
};
app.MapHubs(config);
var configuration = config.Resolver.Resolve<IConfigurationManager>();
// The below effectively sets the heartbeat interval to five seconds.
configuration.KeepAlive = TimeSpan.FromSeconds(10);
var connectionManager = config.Resolver.Resolve<IConnectionManager>();
context = connectionManager.GetHubContext("EchoHub");
});
var cancellationTokenSource = new CancellationTokenSource();
var thread = new Thread(() =>
{
while (!cancellationTokenSource.IsCancellationRequested)
{
context.Clients.All.echo();
}
});
thread.Start();
var connection = new Client.Hubs.HubConnection("http://foo");
var proxy = connection.CreateHubProxy("EchoHub");
try
{
connection.Start(host).Wait();
Thread.Sleep(1000);
}
finally
{
connection.Stop();
}
return new DisposableAction(() =>
{
cancellationTokenSource.Cancel();
thread.Join();
host.Dispose();
});
}
示例5: Connect_Broadcast5msg_AndDisconnect
public static IDisposable Connect_Broadcast5msg_AndDisconnect(int concurrency)
{
var host = new MemoryHost();
var threads = new List<Thread>();
var cancellationTokenSource = new CancellationTokenSource();
host.Configure(app =>
{
var config = new ConnectionConfiguration
{
Resolver = new DefaultDependencyResolver()
};
app.MapConnection<RawConnection>("/Raw-connection", config);
});
for (int i = 0; i < concurrency; i++)
{
var thread = new Thread(_ =>
{
while (!cancellationTokenSource.IsCancellationRequested)
{
BroadcastFive(host);
}
});
threads.Add(thread);
thread.Start();
}
return new DisposableAction(() =>
{
cancellationTokenSource.Cancel();
threads.ForEach(t => t.Join());
host.Dispose();
});
}
示例6: ReconnectFiresAfterHostShutDown
public void ReconnectFiresAfterHostShutDown()
{
using (var host = new MemoryHost())
{
var conn = new MyReconnect();
host.DependencyResolver.Register(typeof(MyReconnect), () => conn);
host.MapConnection<MyReconnect>("/endpoint");
var connection = new Client.Connection("http://foo/endpoint");
connection.Start(host).Wait();
host.Dispose();
Thread.Sleep(TimeSpan.FromSeconds(5));
Assert.Equal(Client.ConnectionState.Reconnecting, connection.State);
connection.Stop();
}
}
示例7: ManyUniqueGroups
public static IDisposable ManyUniqueGroups(int concurrency)
{
var host = new MemoryHost();
var threads = new List<Thread>();
var cancellationTokenSource = new CancellationTokenSource();
host.Configure(app =>
{
var config = new HubConfiguration()
{
Resolver = new DefaultDependencyResolver()
};
app.MapSignalR(config);
});
for (int i = 0; i < concurrency; i++)
{
var thread = new Thread(_ =>
{
while (!cancellationTokenSource.IsCancellationRequested)
{
RunOne(host);
}
});
threads.Add(thread);
thread.Start();
}
return new DisposableAction(() =>
{
cancellationTokenSource.Cancel();
threads.ForEach(t => t.Join());
host.Dispose();
});
}