本文整理汇总了C#中ConcurrentBag.Max方法的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentBag.Max方法的具体用法?C# ConcurrentBag.Max怎么用?C# ConcurrentBag.Max使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConcurrentBag
的用法示例。
在下文中一共展示了ConcurrentBag.Max方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartSimulation
private async Task StartSimulation()
{
if(Simulator.SongData==null)
{
MessageBox.Show("楽曲を選んでください");
return;
}
if (Simulator.Unit == null)
{
MessageBox.Show("ユニットを選んでください");
return;
}
if (Runs < 1 || Runs > 1000000)
{
MessageBox.Show("試行回数は1から1,000,000までである必要があります");
return;
}
Note[] pattern = null;
if (UtilizeActualPattern)
{
pattern = await new PatternProvider().GetPattern(Simulator.Song, Simulator.SongData.Difficulty, Simulator.SongData.Notes);
if (pattern == null)
{
MessageBox.Show($"{Simulator.Song.Title}({Simulator.SongData.Difficulty})の譜面データが見つかりませんでした。");
return;
}
}
SimulationCompleted = false;
var results = new ConcurrentBag<SimulationResult>();
await Task.Run(() => Parallel.For(1, Runs+1, i => results.Add(Simulator.StartSimulation(RandomFactory.Create(), i, pattern == null ? null : new Queue<Note>(pattern)))));
MaxScore = results.Max(x=>x.Score);
MaxScorePerNote = results.Max(x => x.ScorePerNote);
MinScore = results.Min(x => x.Score);
MinScorePerNote = results.Min(x => x.ScorePerNote);
AverageScore = (int)results.Average(x => x.Score);
AverageScorePerNote = (int)results.Average(x => x.ScorePerNote);
ScoreDistribution = results.GroupBy(x => (int)Math.Floor(x.Score / 10000.0)).OrderBy(x => x.Key).ToDictionary(x => x.Key, x => (double)x.Count() / results.Count);
StandardDeviation = Math.Round(Math.Sqrt(results.Sum(x => Math.Pow(x.Score - AverageScore, 2))) / results.Count);
int idx = 1;
var duration = results.First().Duration;
ActualTriggerRatio = Simulator.Unit.Slots.ToDictionary(s => $"スロット{idx++}",
s => s == null ? 0 : results.SelectMany(x => x.TriggeredSkills).Where(x => x.Who == s).Count() / (results.Count * Math.Floor((duration - 1.0) / s.Skill.Interval)));
SimulationResults = results.OrderBy(x => x.Id).Take(100).ToList();
SelectedResult = SimulationResults[0];
SimulationCompleted = true;
}
示例2: StartSimulation
private async Task StartSimulation()
{
if(Simulator.SongData==null)
{
MessageBox.Show("楽曲を選んでください");
return;
}
if (Simulator.Unit == null)
{
MessageBox.Show("ユニットを選んでください");
return;
}
var results = new ConcurrentBag<SimulationResult>();
await Task.Run(() => Parallel.For(1, 101, i => results.Add(Simulator.StartSimulation(RandomFactory.Create(), i))));
MaxScore = results.Max(x=>x.Score);
MaxScorePerNote = results.Max(x => x.ScorePerNote);
MinScore = results.Min(x => x.Score);
MinScorePerNote = results.Min(x => x.ScorePerNote);
AverageScore = (int)results.Average(x => x.Score);
AverageScorePerNote = (int)results.Average(x => x.ScorePerNote);
SimulationResults = results.OrderBy(x => x.Id).ToList();
SelectedResult = SimulationResults[0];
}
示例3: RequestRiverBedHomePageMultiThreaded
private void RequestRiverBedHomePageMultiThreaded(
IMethodLogger logger, int numberOfRequestsToMake, int numberOfThreads)
{
var requestTimes = new ConcurrentBag<long>();
int htmlLength = 0;
try
{
Parallel.For(0, numberOfRequestsToMake,
new ParallelOptions { MaxDegreeOfParallelism = numberOfThreads },
i =>
{
var requestStopWatch = Stopwatch.StartNew();
var webClient = new WebClient();
using (var stream = webClient.OpenRead(new Uri("http://www.riverbed.com")))
// ReSharper disable once AssignNullToNotNullAttribute -- will handle in parent catch
using (var sr = new StreamReader(stream))
{
var html = sr.ReadToEnd();
htmlLength = html.Length;
}
requestTimes.Add(requestStopWatch.ElapsedMilliseconds);
});
}
catch (Exception e)
{
throw new Exception("Error getting http://www.riverbed.com: " + e.Message +
Environment.NewLine + e.StackTrace);
}
logger.WriteMethodInfo(
string.Format("Html Length [{0:n0}] chars. Request Times: Min [{1:n0}] Avg [{2:n0}] Max [{3:n0}]",
htmlLength, requestTimes.Min(), requestTimes.Average(), requestTimes.Max()));
logger.WriteMethodInfo("");
}
示例4: RequestRiverBedHomePageAsync
private void RequestRiverBedHomePageAsync(
IMethodLogger logger, int numberOfRequestsToMake)
{
var requestTimes = new ConcurrentBag<long>();
int htmlLength = 0;
try
{
var tasks =
Enumerable.Range(0, numberOfRequestsToMake)
.Select(async x =>
{
var requestStopWatch = Stopwatch.StartNew();
var webClient = new WebClient();
using (var stream = await webClient.OpenReadTaskAsync(new Uri("http://www.riverbed.com")))
using (var sr = new StreamReader(stream))
{
var html = await sr.ReadToEndAsync();
htmlLength = html.Length;
}
requestTimes.Add(requestStopWatch.ElapsedMilliseconds);
});
Task.WaitAll(tasks.ToArray());
}
catch (Exception e)
{
throw new Exception("Error getting http://www.riverbed.com: " + e.Message +
Environment.NewLine + e.StackTrace);
}
logger.WriteMethodInfo(
string.Format("Html Length [{0:n0}] chars. Request Times: Min [{1:n0}] Avg [{2:n0}] Max [{3:n0}]",
htmlLength, requestTimes.Min(), requestTimes.Average(), requestTimes.Max()));
logger.WriteMethodInfo("");
}
示例5: Main
static void Main(string[] args)
{
// to cover our back for all those fire and forgets
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
Console.ForegroundColor = ConsoleColor.Gray;
ThreadPool.SetMinThreads(200, 100);
ThreadPool.SetMaxThreads(1000, 200);
var statusCodes = new ConcurrentBag<HttpStatusCode>();
var commandLineOptions = new CommandLineOptions();
bool isHelp = args.Any(x => x == "-?");
var success = Parser.Default.ParseArguments(args, commandLineOptions);
var then = DateTime.Now;
ConsoleWriteLine(ConsoleColor.DarkCyan, "Starting at {0}", then) ;
if (!success || isHelp)
{
if (!isHelp && args.Length > 0)
ConsoleWriteLine(ConsoleColor.Red, "error parsing command line");
return;
}
try
{
var requester = new Requester(commandLineOptions);
var writer = new StreamWriter(commandLineOptions.LogFile) { AutoFlush = true };
var stopwatch = Stopwatch.StartNew();
var timeTakens = new ConcurrentBag<double>();
if (commandLineOptions.SaveResponses)
{
if (string.IsNullOrEmpty(commandLineOptions.ResponseFolder))
{
commandLineOptions.ResponseFolder = Path.Combine(Environment.CurrentDirectory, "Responses");
}
if (!Directory.Exists(commandLineOptions.ResponseFolder))
Directory.CreateDirectory(commandLineOptions.ResponseFolder);
}
ConsoleWriteLine(ConsoleColor.Yellow, "[Press C to stop the test]");
int total = 0;
bool disrupted = false;
var stop = new ConsoleKeyInfo();
Console.ForegroundColor = ConsoleColor.Cyan;
var source = new CancellationTokenSource(TimeSpan.FromDays(7));
Task.Run(() =>
{
stop = Console.ReadKey(true);
disrupted = true;
}, source.Token);
var result = Parallel.For(0, commandLineOptions.IsDryRun ? 1 : commandLineOptions.NumberOfRequests,
new ParallelOptions()
{
MaxDegreeOfParallelism = commandLineOptions.Concurrency
},
(i, loopstate) =>
{
if (disrupted)
{
ConsoleWriteLine(ConsoleColor.Red, "...");
ConsoleWriteLine(ConsoleColor.Green, "Exiting.... please wait! (it might throw a few more requests)");
ConsoleWriteLine(ConsoleColor.Red, "");
loopstate.Stop();
source.Cancel();
}
var sw = Stopwatch.StartNew();
IDictionary<string, object> parameters;
var statusCode = requester.Next(i, out parameters);
sw.Stop();
if (commandLineOptions.DelayInMillisecond > 0)
{
Thread.Sleep(commandLineOptions.DelayInMillisecond);
}
statusCodes.Add(statusCode);
timeTakens.Add(sw.ElapsedTicks);
var n = Interlocked.Increment(ref total);
// fire and forget not to affect time taken or TPS
Task.Run(() =>
WriteLine(writer, n, (int)statusCode, sw.ElapsedMilliseconds, parameters));
if (!commandLineOptions.Verbose)
Console.Write("\r" + total);
}
);
stopwatch.Stop();
double[] orderedList = (from x in timeTakens
orderby x
select x).ToArray<double>();
Console.WriteLine();
ConsoleWriteLine(ConsoleColor.Magenta, "---------------Finished!----------------");
var now = DateTime.Now;
//.........这里部分代码省略.........