# Async/await とパターン (.NET) > async/await、Task、ValueTask、ConfigureAwait、cancellation token、並列実行、deadlock - 26 面接問題 - Senior - [面接問題: .NET](https://sharpskill.dev/ja/technologies/dotnet/interview-questions.md) ## 1. 非同期メソッドにおける 'await' キーワードの主な役割は何ですか? **回答** await キーワードは Task が完了するまで非同期メソッドの実行を中断し、その間、呼び出し元の thread を解放して他のタスクを処理できるようにします。これにより thread のブロックを回避し、アプリケーションのスケーラビリティを向上させます。thread をブロックする Task.Wait() や Task.Result とは異なり、await は thread pool リソースを効率的に利用できます。 ## 2. イベントハンドラーを除いて async void を避けるべきなのはなぜですか? **回答** async void メソッドは await できず、内部でスローされた例外は呼び出し元のコードでキャッチできないため、アプリケーションがクラッシュします。さらに、await すべき Task がないため、async void メソッドの単体テストは不可能です。イベントハンドラーは framework から呼び出され Task を返せないため、例外となります。 ## 3. どのようなユースケースで Task よりも ValueTask を優先すべきですか? **回答** ValueTask は value type であり、結果が cache のように既に同期的に利用可能な場合に heap 割り当てを回避します。これにより高パフォーマンスのシナリオで garbage collector への負荷を軽減します。Task は結果が同期的であっても常に heap に割り当てられます。誤った使用はパフォーマンスを低下させる可能性があるため、パフォーマンスの向上が測定可能な場合のみ ValueTask を使用してください。 ## さらに23問利用可能 - Task と比較して ValueTask に適用される重要な制約は何ですか? - .NET ライブラリにおける ConfigureAwait(false) の主な目的は何ですか? 無料で登録: https://sharpskill.dev/ja/login ## その他の.NET面接トピック - [C# の基礎](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/csharp-basics.md): 25問, Junior - [LINQ & Delegates](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/csharp-linq-delegates.md): 20問, Junior - [C#言語の基礎](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/csharp-language-essentials.md): 15問, Junior - [ASP.NET Core の基礎](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/aspnet-core-fundamentals.md): 18問, Junior - [ASP.NET Core のリクエストライフサイクル](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/aspnet-core-request-lifecycle.md): 20問, Junior - [Configuration & Settings](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/configuration-settings.md): 20問, Junior - [アプリケーションのライフサイクル](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/application-lifecycle.md): 20問, Junior - [Dependency Injection](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/dependency-injection.md): 24問, Mid-Level - [Entity Framework Core](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/entity-framework-core.md): 25問, Mid-Level - [Minimal APIs](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/minimal-apis.md): 18問, Mid-Level - [Web API開発](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/web-api-development.md): 22問, Mid-Level - [ASP.NET Core における Async](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/async-aspnet-core.md): 20問, Mid-Level - [Authentication & Authorization](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/authentication-authorization.md): 18問, Mid-Level - [HttpClient & ネットワーキング](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/httpclient-networking.md): 20問, Mid-Level - [JSONシリアライズ](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/json-serialization.md): 20問, Mid-Level - [Entity Framework Core 応用](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/ef-core-advanced.md): 25問, Mid-Level - [C# の高度な機能](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/csharp-advanced-features.md): 20問, Mid-Level - [Clean Architecture](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/clean-architecture.md): 20問, Mid-Level - [Logging, Monitoring & Observability](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/logging-monitoring.md): 22問, Mid-Level - [ユニットテストとxUnit](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/unit-testing-xunit.md): 20問, Mid-Level - [統合テスト](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/integration-testing.md): 18問, Mid-Level - [Docker & Containerization](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/docker-containerization.md): 16問, Mid-Level - [NuGet パッケージ管理](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/nuget-package-management.md): 16問, Mid-Level - [Memory Management & GC](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/memory-management-gc.md): 22問, Senior - [リアクティブプログラミング](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/reactive-programming.md): 24問, Senior - [.NET デザインパターン](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/dotnet-design-patterns.md): 24問, Senior - [パフォーマンス最適化](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/performance-optimization.md): 22問, Senior - [セキュリティとベストプラクティス](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/security-best-practices.md): 24問, Senior - [SignalR とリアルタイム](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/signalr-realtime.md): 22問, Senior - [マイクロサービスアーキテクチャ](https://sharpskill.dev/ja/technologies/dotnet/interview-questions/microservices-architecture.md): 25問, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/ja/technologies/dotnet/interview-questions/async-await-patterns