{"id":408156,"date":"2024-06-29T19:59:08","date_gmt":"2024-06-29T19:59:08","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=408156"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2024-06-29T19:59:08","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=408156","title":{"rendered":"<span>\u041d\u043e\u0432\u044b\u0435 API \u0432 .NET 6<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>.NET 6 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-net-6-preview-7\/\">\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438<\/a>, \u0438 \u044f \u0445\u043e\u0442\u0435\u043b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0438\u0437 \u043c\u043e\u0438\u0445 \u043b\u044e\u0431\u0438\u043c\u044b\u0445 \u043d\u043e\u0432\u044b\u0445 API \u0432 .NET \u0438 ASP.NET Core, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0430\u043c \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u043d\u0440\u0430\u0432\u044f\u0442\u0441\u044f. \u041f\u043e\u0447\u0435\u043c\u0443 \u043e\u043d\u0438 \u043f\u043e\u043d\u0440\u0430\u0432\u044f\u0442\u0441\u044f? \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u044b \u043f\u0440\u0438 \u043f\u0440\u044f\u043c\u043e\u043c \u0443\u0447\u0430\u0441\u0442\u0438\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u0444\u0430\u043d\u0442\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 .NET. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435.<\/p>\n<h2>\u0427\u0442\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0444\u0430\u0439\u043b\u043e\u0432 <\/h2>\n<p>\u0412 .NET 6 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0439 API, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u0447\u0438\u0442\u0430\u0442\u044c\/\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f FileStream. \u041e\u043d \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 scatter\/gather IO (\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0443\u0444\u0435\u0440\u043e\u0432) \u0438 \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0449\u0438\u0435\u0441\u044f \u0447\u0442\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u043f\u0440\u0438 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0438 \u0444\u0430\u0439\u043b\u0430 (file offset).<\/p>\n<pre><code class=\"cs\">using Microsoft.Win32.SafeHandles; using SafeFileHandle handle = File.OpenHandle(\"ConsoleApp128.exe\"); long length = RandomAccess.GetLength(handle);  Console.WriteLine(length);<\/code><\/pre>\n<h2>\u041f\u0443\u0442\u044c \u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 <\/h2>\n<p>\u0415\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u043e\u0432\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043f\u0443\u0442\u0438 \u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0431\u0435\u0437 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430: <\/p>\n<pre><code class=\"cs\">int pid = Environment.ProcessId; string path = Environment.ProcessPath;  Console.WriteLine(pid); Console.WriteLine(path);<\/code><\/pre>\n<h2>CSPNG (\u043a\u0440\u0438\u043f\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u043f\u0441\u0435\u0432\u0434\u043e\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b) <\/h2>\n<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0438\u0437 CSPNG (\u043a\u0440\u0438\u043f\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0433\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u0441\u0435\u0432\u0434\u043e\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b) \u0441\u0442\u0430\u043b\u0430 \u043f\u0440\u043e\u0449\u0435, \u0447\u0435\u043c \u043a\u043e\u0433\u0434\u0430-\u043b\u0438\u0431\u043e: <\/p>\n<pre><code class=\"cs\">\/\/ \u0414\u0430\u0439 \u043c\u043d\u0435 200 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 bytes  byte[] bytes = RandomNumberGenerator.GetBytes(200);<\/code><\/pre>\n<h3>Parallel.ForEachAsync<\/h3>\n<p>\u041c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 Parallel.ForEachAsync, \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u0430\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0435\u043f\u0435\u043d\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c\u0430:<\/p>\n<pre><code class=\"cs\">var urlsToDownload = new []  {     \"https:\/\/dotnet.microsoft.com\",     \"https:\/\/www.microsoft.com\",     \"https:\/\/twitter.com\/davidfowl\" };  var client = new HttpClient();  await Parallel.ForEachAsync(urlsToDownload, async (url, token) => {     var targetPath = Path.Combine(Path.GetTempPath(), \"http_cache\", url);      HttpResponseMessage response = await client.GetAsync(url);      if (response.IsSuccessStatusCode)     {         using FileStream target = File.OpenWrite(targetPath);          await response.Content.CopyToAsync(target);     }<\/code><\/pre>\n<h2>\u041f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0438 \u043f\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 <\/h2>\n<p>\u041c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a, \u0447\u0442\u043e\u0431\u044b \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0441\u0431\u0440\u043e\u0441, \u0435\u0441\u043b\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"cs\">var configuration = new ConfigurationManager(); var options = new MyOptions();  configuration.GetRequiredSection(\"MyOptions\").Bind(options);  class MyOptions {     public string? SettingValue { get; set;}<\/code><\/pre>\n<h3>LINQ<\/h3>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u043c\u0430\u0441\u0441\u0430 \u043d\u043e\u0432\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 LINQ. \u0412\u043e\u0442 \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a \u0434\u043b\u044f \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u043b\u044e\u0431\u043e\u0433\u043e IEnumerable \u043d\u0430 \u043f\u0430\u043a\u0435\u0442\u044b: <\/p>\n<pre><code class=\"cs\">int chunkNumber = 1; foreach (int[] chunk in Enumerable.Range(0, 9).Chunk(3)) {     Console.WriteLine($\"Chunk {chunkNumber++}\");     foreach (var item in chunk)     {         Console.WriteLine(item);     } }<\/code><\/pre>\n<h2>\u0415\u0449\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 LINQ<\/h2>\n<p>\u0411\u043e\u043b\u044c\u0448\u0435 LINQ! \u0422\u0435\u043f\u0435\u0440\u044c \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b MaxBy \u0438 MinBy: <\/p>\n<pre><code class=\"cs\">var people = GetPeople();  var oldest = people.MaxBy(p => p.Age); var youngest = people.MinBy(p => p.Age);  Console.WriteLine($\"The oldest person is {oldest.Age}\"); Console.WriteLine($\"The youngest person is {youngest.Age}\");  public record Person(string Name, int Age);<\/code><\/pre>\n<h2>\u0412\u0442\u043e\u0440\u0430\u044f \u0441\u0442\u0435\u043f\u0435\u043d\u044c<\/h2>\n<p>\u041d\u0435 \u0434\u0435\u0440\u0436\u0438\u0442\u0435 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0443 \u0432 \u0433\u043e\u043b\u043e\u0432\u0435? \u0418 \u044f \u043d\u0435\u0442. \u0412\u043e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u043e\u0432\u044b\u0445 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u043e\u0432 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u044c\u044e: <\/p>\n<pre><code class=\"cs\">using System.Numerics;  uint bufferSize = 235; if (!BitOperations.IsPow2(bufferSize)) {     bufferSize = BitOperations.RoundUpToPowerOf2(bufferSize); }  Console.WriteLine(bufferSize);<\/code><\/pre>\n<h2>\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f WaitAsync <\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 (\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439) \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0432\u0435\u0440\u043d\u0435\u0442 await, \u0435\u0441\u043b\u0438 \u043e\u043d \u043d\u0435 \u0431\u044b\u043b \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 10 \u0441\u0435\u043a\u0443\u043d\u0434. \u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0435\u0449\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c\u0441\u044f. \u042d\u0442\u043e \u0434\u043b\u044f \u043d\u0435\u043e\u0442\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439.<\/p>\n<pre><code class=\"cs\">Task operationTask = SomeLongRunningOperationAsync();  await operationTask.WaitAsync(TimeSpan.FromSeconds(10));<\/code><\/pre>\n<h3>ThrowIfNull<\/h3>\n<p>\u0411\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 null \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u0441\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043e\u0434\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0430 \u043a\u043e\u0434\u0430.<\/p>\n<pre><code class=\"cs\">void DoSomethingUseful(object obj) {     ArgumentNullException.ThrowIfNull(obj); }<\/code><\/pre>\n<h2>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 NativeMemory<\/h2>\n<pre><code class=\"cs\">using System.Runtime.InteropServices;  unsafe {     byte* buffer = (byte*)NativeMemory.Alloc(100);      NativeMemory.Free(buffer); }<\/code><\/pre>\n<h2>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432 Posix <\/h2>\n<p>\u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432 Posix \u0437\u0434\u0435\u0441\u044c, \u0438 \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u044d\u043c\u0443\u043b\u0438\u0440\u0443\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432 \u0432 Windows. <\/p>\n<pre><code class=\"cs\">using System.Runtime.InteropServices;  var tcs = new TaskCompletionSource();  PosixSignalRegistration.Create(PosixSignal.SIGTERM, context => {     Console.WriteLine($\"{context.Signal} fired\");     tcs.TrySetResult(); });  await tcs.Task;<\/code><\/pre>\n<h2>\u041d\u043e\u0432\u044b\u0439 API \u043c\u0435\u0442\u0440\u0438\u043a <\/h2>\n<p>\u041c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u043e\u0432\u044b\u0439 API \u043c\u0435\u0442\u0440\u0438\u043a, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 @opentelemetry \u0432 .NET 6. \u041e\u043d \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f, \u0441\u0443\u043f\u0435\u0440\u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u0435\u043d \u0438 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0435\u0440\u044b \u0434\u043b\u044f \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u043c\u0435\u0442\u0440\u0438\u043a. <\/p>\n<pre><code class=\"cs\">using System.Diagnostics.Metrics;  \/\/ \u0412\u043e\u0442 \u043a\u0430\u043a \u0432\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438   var meter = new Meter(\"Microsoft.AspNetCore\", \"v1.0\"); Counter&lt;int> counter = meter.CreateCounter&lt;int>(\"Requests\");  var app = WebApplication.Create(args);  app.Use((context, next) => {     counter.Add(1, KeyValuePair.Create&lt;string, object?>(\"path\", context.Request.Path.ToString()));     return next(context); });  app.MapGet(\"\/\", () => \"Hello World\");<\/code><\/pre>\n<p>\u0412\u044b \u0434\u0430\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 listen \u0438 meter: <\/p>\n<pre><code class=\"cs\">var listener = new MeterListener(); listener.InstrumentPublished = (instrument, meterListener) => {     if(instrument.Name == \"Requests\" &amp;&amp; instrument.Meter.Name == \"Microsoft.AspNetCore\")     {         meterListener.EnableMeasurementEvents(instrument, null);     } };  listener.SetMeasurementEventCallback&lt;int>((instrument, measurement, tags, state) => {     Console.WriteLine($\"Instrument: {instrument.Name} has recorded the measurement: {measurement}\"); });  listener.Start();<\/code><\/pre>\n<h2>API \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0430\u0439\u043c\u0435\u0440\u0430 <\/h2>\n<p>\u0418 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435, \u043d\u043e \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0432\u0430\u0436\u043d\u043e\u0435: \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 API \u0442\u0430\u0439\u043c\u0435\u0440\u0430 (\u044f \u0434\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u044d\u0442\u043e \u0443\u0436\u0435 \u043f\u044f\u0442\u044b\u0439 API \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u0432 .NET). \u041e\u043d \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0435\u043d \u0438 \u043d\u0435 \u043f\u043e\u0434\u0432\u0435\u0440\u0436\u0435\u043d \u0442\u0438\u043f\u0430\u043c \u043e\u0448\u0438\u0431\u043e\u043a, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0434\u0440\u0443\u0433\u0438\u0435 \u0442\u0430\u0439\u043c\u0435\u0440\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0438\u0437\u043d\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435\u043c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0438 \u0442.\u0434.<\/p>\n<pre><code class=\"cs\">var timer = new PeriodicTimer(TimeSpan.FromSeconds(1));  while (await timer.WaitForNextTickAsync()) {     Console.WriteLine(DateTime.UtcNow); }<\/code><\/pre>\n<h3>Summary<\/h3>\n<p>\u042d\u0442\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043d\u043e\u0432\u044b\u0445 API, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u044f\u0432\u044f\u0442\u0441\u044f \u0432 .NET 6. \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0441\u043c. <a href=\"https:\/\/github.com\/dotnet\/core\/tree\/main\/release-notes\/6.0\/preview\/api-diff\">\u0420\u0430\u0437\u043b\u0438\u0447\u0438\u044f API, \u043f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0439 \u043a \u0432\u044b\u043f\u0443\u0441\u043a\u0443 .NET 6<\/a>. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0421\u0442\u0438\u0432\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0432\u043f\u0435\u0447\u0430\u0442\u043b\u044f\u044e\u0449\u0438\u0439 <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/performance-improvements-in-net-6\/\">\u043f\u043e\u0441\u0442<\/a> \u043e\u0431 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432 .NET6, \u0442\u0430\u043a \u0447\u0442\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0447\u0442\u0438\u0442\u0435 \u0435\u0433\u043e. \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 <a href=\"https:\/\/dot.net\/download\">\u0441\u043a\u0430\u0447\u0430\u0442\u044c<\/a> \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e .NET 6 \u0438 \u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 API \u0443\u0436\u0435 \u0441\u0435\u0433\u043e\u0434\u043d\u044f.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/574434\/\"> https:\/\/habr.com\/ru\/articles\/574434\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>.NET 6 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-net-6-preview-7\/\">\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438<\/a>, \u0438 \u044f \u0445\u043e\u0442\u0435\u043b \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0438\u0437 \u043c\u043e\u0438\u0445 \u043b\u044e\u0431\u0438\u043c\u044b\u0445 \u043d\u043e\u0432\u044b\u0445 API \u0432 .NET \u0438 ASP.NET Core, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0430\u043c \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u043e\u043d\u0440\u0430\u0432\u044f\u0442\u0441\u044f. \u041f\u043e\u0447\u0435\u043c\u0443 \u043e\u043d\u0438 \u043f\u043e\u043d\u0440\u0430\u0432\u044f\u0442\u0441\u044f? \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u043e\u043d\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u044b \u043f\u0440\u0438 \u043f\u0440\u044f\u043c\u043e\u043c \u0443\u0447\u0430\u0441\u0442\u0438\u0438 \u043d\u0430\u0448\u0435\u0433\u043e \u0444\u0430\u043d\u0442\u0430\u0441\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u0441\u0442\u0432\u0430 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 .NET. \u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435.<\/p>\n<h2>\u0427\u0442\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0444\u0430\u0439\u043b\u043e\u0432 <\/h2>\n<p>\u0412 .NET 6 \u043f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u043d\u043e\u0432\u044b\u0439 \u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u0439 API, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0438\u0439 \u0447\u0438\u0442\u0430\u0442\u044c\/\u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b\u044b \u0431\u0435\u0437 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f FileStream. \u041e\u043d \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 scatter\/gather IO (\u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0431\u0443\u0444\u0435\u0440\u043e\u0432) \u0438 \u0434\u0443\u0431\u043b\u0438\u0440\u0443\u044e\u0449\u0438\u0435\u0441\u044f \u0447\u0442\u0435\u043d\u0438\u0435 \u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u043f\u0440\u0438 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0438 \u0444\u0430\u0439\u043b\u0430 (file offset).<\/p>\n<pre><code class=\"cs\">using Microsoft.Win32.SafeHandles; using SafeFileHandle handle = File.OpenHandle(\"ConsoleApp128.exe\"); long length = RandomAccess.GetLength(handle);  Console.WriteLine(length);<\/code><\/pre>\n<h2>\u041f\u0443\u0442\u044c \u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 <\/h2>\n<p>\u0415\u0441\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u043e\u0432\u044b\u0445 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u043f\u0443\u0442\u0438 \u0438 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0431\u0435\u0437 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430: <\/p>\n<pre><code class=\"cs\">int pid = Environment.ProcessId; string path = Environment.ProcessPath;  Console.WriteLine(pid); Console.WriteLine(path);<\/code><\/pre>\n<h2>CSPNG (\u043a\u0440\u0438\u043f\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440 \u043f\u0441\u0435\u0432\u0434\u043e\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b) <\/h2>\n<p>\u0413\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b \u0438\u0437 CSPNG (\u043a\u0440\u0438\u043f\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0447\u0435\u0441\u043a\u0438 \u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u043e\u0433\u043e \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u043e\u0440\u0430 \u043f\u0441\u0435\u0432\u0434\u043e\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 \u0447\u0438\u0441\u0435\u043b) \u0441\u0442\u0430\u043b\u0430 \u043f\u0440\u043e\u0449\u0435, \u0447\u0435\u043c \u043a\u043e\u0433\u0434\u0430-\u043b\u0438\u0431\u043e: <\/p>\n<pre><code class=\"cs\">\/\/ \u0414\u0430\u0439 \u043c\u043d\u0435 200 \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u0445 bytes  byte[] bytes = RandomNumberGenerator.GetBytes(200);<\/code><\/pre>\n<h3>Parallel.ForEachAsync<\/h3>\n<p>\u041c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 Parallel.ForEachAsync, \u0441\u043f\u043e\u0441\u043e\u0431 \u043f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u0430\u043c \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0435\u043f\u0435\u043d\u044c \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u0438\u0437\u043c\u0430:<\/p>\n<pre><code class=\"cs\">var urlsToDownload = new []  {     \"https:\/\/dotnet.microsoft.com\",     \"https:\/\/www.microsoft.com\",     \"https:\/\/twitter.com\/davidfowl\" };  var client = new HttpClient();  await Parallel.ForEachAsync(urlsToDownload, async (url, token) => {     var targetPath = Path.Combine(Path.GetTempPath(), \"http_cache\", url);      HttpResponseMessage response = await client.GetAsync(url);      if (response.IsSuccessStatusCode)     {         using FileStream target = File.OpenWrite(targetPath);          await response.Content.CopyToAsync(target);     }<\/code><\/pre>\n<h2>\u041f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u0438 \u043f\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 <\/h2>\n<p>\u041c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a, \u0447\u0442\u043e\u0431\u044b \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0441\u0431\u0440\u043e\u0441, \u0435\u0441\u043b\u0438 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u0442\u0440\u0435\u0431\u0443\u0435\u043c\u044b\u0439 \u0440\u0430\u0437\u0434\u0435\u043b \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438:<\/p>\n<pre><code class=\"cs\">var configuration = new ConfigurationManager(); var options = new MyOptions();  configuration.GetRequiredSection(\"MyOptions\").Bind(options);  class MyOptions {     public string? SettingValue { get; set;}<\/code><\/pre>\n<h3>LINQ<\/h3>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0435\u0441\u0442\u044c \u043c\u0430\u0441\u0441\u0430 \u043d\u043e\u0432\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 LINQ. \u0412\u043e\u0442 \u043d\u043e\u0432\u044b\u0439 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a \u0434\u043b\u044f \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u043b\u044e\u0431\u043e\u0433\u043e IEnumerable \u043d\u0430 \u043f\u0430\u043a\u0435\u0442\u044b: <\/p>\n<pre><code class=\"cs\">int chunkNumber = 1; foreach (int[] chunk in Enumerable.Range(0, 9).Chunk(3)) {     Console.WriteLine($\"Chunk {chunkNumber++}\");     foreach (var item in chunk)     {         Console.WriteLine(item);     } }<\/code><\/pre>\n<h2>\u0415\u0449\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 LINQ<\/h2>\n<p>\u0411\u043e\u043b\u044c\u0448\u0435 LINQ! \u0422\u0435\u043f\u0435\u0440\u044c \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434\u044b MaxBy \u0438 MinBy: <\/p>\n<pre><code class=\"cs\">var people = GetPeople();  var oldest = people.MaxBy(p => p.Age); var youngest = people.MinBy(p => p.Age);  Console.WriteLine($\"The oldest person is {oldest.Age}\"); Console.WriteLine($\"The youngest person is {youngest.Age}\");  public record Person(string Name, int Age);<\/code><\/pre>\n<h2>\u0412\u0442\u043e\u0440\u0430\u044f \u0441\u0442\u0435\u043f\u0435\u043d\u044c<\/h2>\n<p>\u041d\u0435 \u0434\u0435\u0440\u0436\u0438\u0442\u0435 \u043c\u0430\u0442\u0435\u043c\u0430\u0442\u0438\u043a\u0443 \u0432 \u0433\u043e\u043b\u043e\u0432\u0435? \u0418 \u044f \u043d\u0435\u0442. \u0412\u043e\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u043e\u0432\u044b\u0445 \u043f\u043e\u043c\u043e\u0449\u043d\u0438\u043a\u043e\u0432 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u0435\u043f\u0435\u043d\u044c\u044e: <\/p>\n<pre><code class=\"cs\">using System.Numerics;  uint bufferSize = 235; if (!BitOperations.IsPow2(bufferSize)) {     bufferSize = BitOperations.RoundUpToPowerOf2(bufferSize); }  Console.WriteLine(bufferSize);<\/code><\/pre>\n<h2>\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f WaitAsync <\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 (\u0438 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439) \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u044f \u0437\u0430\u0434\u0430\u0447\u0438. \u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0432\u0435\u0440\u043d\u0435\u0442 await, \u0435\u0441\u043b\u0438 \u043e\u043d \u043d\u0435 \u0431\u044b\u043b \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d \u0432 \u0442\u0435\u0447\u0435\u043d\u0438\u0435 10 \u0441\u0435\u043a\u0443\u043d\u0434. \u041e\u043f\u0435\u0440\u0430\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u0435\u0449\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0430\u0442\u044c\u0441\u044f. \u042d\u0442\u043e \u0434\u043b\u044f \u043d\u0435\u043e\u0442\u043c\u0435\u043d\u044f\u0435\u043c\u044b\u0445 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439.<\/p>\n<pre><code class=\"cs\">Task operationTask = SomeLongRunningOperationAsync();  await operationTask.WaitAsync(TimeSpan.FromSeconds(10));<\/code><\/pre>\n<h3>ThrowIfNull<\/h3>\n<p>\u0411\u043e\u043b\u044c\u0448\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 null \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u043c\u0435\u0442\u043e\u0434\u0435 \u043f\u0435\u0440\u0435\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a \u0441\u0431\u0440\u043e\u0441\u0438\u0442\u044c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435. \u0422\u0435\u043f\u0435\u0440\u044c \u044d\u0442\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043e\u0434\u043d\u0430 \u0441\u0442\u0440\u043e\u043a\u0430 \u043a\u043e\u0434\u0430.<\/p>\n<pre><code class=\"cs\">void DoSomethingUseful(object obj) {     ArgumentNullException.ThrowIfNull(obj); }<\/code><\/pre>\n<h2>\u0420\u0430\u0431\u043e\u0442\u0430 \u0441 NativeMemory<\/h2>\n<pre><code class=\"cs\">using System.Runtime.InteropServices;  unsafe {     byte* buffer = (byte*)NativeMemory.Alloc(100);      NativeMemory.Free(buffer); }<\/code><\/pre>\n<h2>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432 Posix <\/h2>\n<p>\u0412\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u0430\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432 Posix \u0437\u0434\u0435\u0441\u044c, \u0438 \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u044d\u043c\u0443\u043b\u0438\u0440\u0443\u0435\u043c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432 \u0432 Windows. <\/p>\n<pre><code class=\"cs\">using System.Runtime.InteropServices;  var tcs = new TaskCompletionSource();  PosixSignalRegistration.Create(PosixSignal.SIGTERM, context => {     Console.WriteLine($\"{context.Signal} fired\");     tcs.TrySetResult(); });  await tcs.Task;<\/code><\/pre>\n<h2>\u041d\u043e\u0432\u044b\u0439 API \u043c\u0435\u0442\u0440\u0438\u043a <\/h2>\n<p>\u041c\u044b \u0434\u043e\u0431\u0430\u0432\u0438\u043b\u0438 \u0441\u043e\u0432\u0435\u0440\u0448\u0435\u043d\u043d\u043e \u043d\u043e\u0432\u044b\u0439 API \u043c\u0435\u0442\u0440\u0438\u043a, \u043e\u0441\u043d\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043d\u0430 @opentelemetry \u0432 .NET 6. \u041e\u043d \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0438\u0437\u043c\u0435\u0440\u0435\u043d\u0438\u044f, \u0441\u0443\u043f\u0435\u0440\u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u0435\u043d \u0438 \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0435\u0440\u044b \u0434\u043b\u044f \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0445 \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u0432 \u043c\u0435\u0442\u0440\u0438\u043a. <\/p>\n<pre><code class=\"cs\">using System.Diagnostics.Metrics;  \/\/ \u0412\u043e\u0442 \u043a\u0430\u043a \u0432\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435 \u043c\u0435\u0442\u0440\u0438\u043a\u0438   var meter = new Meter(\"Microsoft.AspNetCore\", \"v1.0\"); Counter&lt;int> counter = meter.CreateCounter&lt;int>(\"Requests\");  var app = WebApplication.Create(args);  app.Use((context, next) => {     counter.Add(1, KeyValuePair.Create&lt;string, object?>(\"path\", context.Request.Path.ToString()));     return next(context); });  app.MapGet(\"\/\", () => \"Hello World\");<\/code><\/pre>\n<p>\u0412\u044b \u0434\u0430\u0436\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 listen \u0438 meter: <\/p>\n<pre><code class=\"cs\">var listener = new MeterListener(); listener.InstrumentPublished = (instrument, meterListener) => {     if(instrument.Name == \"Requests\" &amp;&amp; instrument.Meter.Name == \"Microsoft.AspNetCore\")     {         meterListener.EnableMeasurementEvents(instrument, null);     } };  listener.SetMeasurementEventCallback&lt;int>((instrument, measurement, tags, state) => {     Console.WriteLine($\"Instrument: {instrument.Name} has recorded the measurement: {measurement}\"); });  listener.Start();<\/code><\/pre>\n<h2>API \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0442\u0430\u0439\u043c\u0435\u0440\u0430 <\/h2>\n<p>\u0418 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0435, \u043d\u043e \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u0432\u0430\u0436\u043d\u043e\u0435: \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0439 API \u0442\u0430\u0439\u043c\u0435\u0440\u0430 (\u044f \u0434\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u044d\u0442\u043e \u0443\u0436\u0435 \u043f\u044f\u0442\u044b\u0439 API \u0442\u0430\u0439\u043c\u0435\u0440\u0430 \u0432 .NET). \u041e\u043d \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0435\u043d \u0438 \u043d\u0435 \u043f\u043e\u0434\u0432\u0435\u0440\u0436\u0435\u043d \u0442\u0438\u043f\u0430\u043c \u043e\u0448\u0438\u0431\u043e\u043a, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0434\u0440\u0443\u0433\u0438\u0435 \u0442\u0430\u0439\u043c\u0435\u0440\u044b, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0436\u0438\u0437\u043d\u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435\u043c \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u0445 \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 \u0438 \u0442.\u0434.<\/p>\n<pre><code class=\"cs\">var timer = new PeriodicTimer(TimeSpan.FromSeconds(1));  while (await timer.WaitForNextTickAsync()) {     Console.WriteLine(DateTime.UtcNow); }<\/code><\/pre>\n<h3>Summary<\/h3>\n<p>\u042d\u0442\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u043d\u043e\u0432\u044b\u0445 API, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u044f\u0432\u044f\u0442\u0441\u044f \u0432 .NET 6. \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0441\u043c. <a href=\"https:\/\/github.com\/dotnet\/core\/tree\/main\/release-notes\/6.0\/preview\/api-diff\">\u0420\u0430\u0437\u043b\u0438\u0447\u0438\u044f API, \u043f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0439 \u043a \u0432\u044b\u043f\u0443\u0441\u043a\u0443 .NET 6<\/a>. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u0421\u0442\u0438\u0432\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0432\u043f\u0435\u0447\u0430\u0442\u043b\u044f\u044e\u0449\u0438\u0439 <a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/performance-improvements-in-net-6\/\">\u043f\u043e\u0441\u0442<\/a> \u043e\u0431 \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432 .NET6, \u0442\u0430\u043a \u0447\u0442\u043e \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0447\u0442\u0438\u0442\u0435 \u0435\u0433\u043e. \u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u043d\u0435 \u0437\u0430\u0431\u0443\u0434\u044c\u0442\u0435 <a href=\"https:\/\/dot.net\/download\">\u0441\u043a\u0430\u0447\u0430\u0442\u044c<\/a> \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e .NET 6 \u0438 \u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0435 API \u0443\u0436\u0435 \u0441\u0435\u0433\u043e\u0434\u043d\u044f.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/574434\/\"> https:\/\/habr.com\/ru\/articles\/574434\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-408156","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/408156","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=408156"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/408156\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=408156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=408156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=408156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}