Is there a possibility to use thread static like variables within a single request? The current code uses a thread static variable for logging purposes and now we want to use async controller methods (with async and await pattern) which results in problems because the variable is null when a new thread is opened.
ThreadStatic in asynchronous ASP.NET Web API
2k Views Asked by Nico At
1
There are 1 best solutions below
Related Questions in ASP.NET
- Implementing Azure AD B2C Authentication in .NET 8 Blazor Project (RenderMode: InteractiveAuto)
- Azure Application Insights Not Displaying Custom Logs for Azure Functions with .NET 8
- IIS Rewrite Module exclude bots but allow GoogleBot
- Angular 16 sending null values to API
- I am the domain admin, newbie, how do I connect youtube.com on my domain?
- Dropdown list showing SQLServer2005SQLBrowserUser$DONSERVER instead of Active Directory group name in ASP.NET MVC C#
- ASP.NET Identity, Losing Ability to Login until Application Pool Recycles
- How to unprotect ASP.NET FormAuthentication cookie
- How does it work using ASP.NET FormAuthentication
- What is the purpose of a completely standalone 'this'?
- Is there a way to read .csproj PropertyGroup variable in c#
- MSBuild trying to copy different dll with similar name into project sporadically
- Minimizing IdentityServer4 Round Trips in Microservice Architecture with Ocelot
- Azure AD guest account in web app authentication user claims data
- Receiving 400 bad request on post when customer auth handler is used
Related Questions in ASP.NET-WEB-API
- Log to Dynatrace using Serilog and web.config .NET Framework API
- How to create a REST API with .NET Framework?
- ASP.NET Core Background task with service container
- App gateway closing connection after 100 requests
- Web API works with Windows authentication enabled when consumed via Swagger but throws an unauthorized issue when accessed through web app
- The 'GetUriByAction' method in the LinkGenerator class in Asp.Net Core is not defined in the Repository layer of the project
- Entity Tracking Conflict when Authenticating Users in ASP.NET Core API
- Class validation on response body in .NET WebApi
- My ASP.NET server does not work and I am wondering what's missing, when I open Swagger, I get error 500
- How to split Serilog log file into multiple files?
- Response payload is not odata payload
- How can I upload picture
- Web Forms aspx - PostAsync Web API
- do you know any free reporting services like devexpress or boldreports?
- WebAPI don't deserialize JSON but same payload works in Swagger
Related Questions in ASYNC-AWAIT
- C# Console app do not exit until CTRL+C pressed without while loop
- Hooks are not supported inside an async component error in nextjs project using useQuery
- Vue3 Suspense Parent > Child Animation
- How to schedule the execution of broadcast tasks from a queue of to be broadcasted data with a one second delay in between each broadcast invocation?
- async/await is not yet supported in Client Components when using await supabase
- Adding SwiftData model operations in Task{} block caused EXC_BAD_ACCESS using swift-async-dns-resolver
- Why use tasks and async await in C# inline?
- inferred to be a `FnMut` closure
- Blocking wait on future OUTSIDE of async functions
- Can asyncio.sleep be stopped?
- How to crawl 5000 different URLs to find certain links
- React-native Long-polling or SignalR/websocket?
- When is omitting await acceptable in asynchronous functions?
- Issue with service method call in .NET Background Service , Issue with Scope
- **dotnet core console** app: ConfigureAwait(true)
Related Questions in THREADSTATIC
- Losing [ThreadStatic] value after calling a Task
- .Net Core 3.1.6 ThreadLocal / ThreadStatic
- ASP.NET MVC 5 - can the current thread change during single http request?
- Disposing thread static variable
- Object reference error while instantiating non static class in multiple threads
- Accessing ThreadStatic field from .NET profiler
- CallContext is carrying foreward the previous data which was set
- C# Singleton Pattern Designs for ThreadStatic
- What's the effect of AsyncLocal<T> in non async/await code?
- ThreadStatic in asynchronous ASP.NET Web API
- Why Initializing threadstatic attribute in Threadlocal delegate doesn't initilize it for the first thread?
- ThreadStatic Atttribute in Thread vs Task
- CRM 2011 OrganizationService Disposed
- Is the use of [ThreadStatic] at odds with asynchronous code?
- Creating thread safe variable in c#
Related Questions in REQUESTSCOPE
- NestJS Mongoose Request-Scoped Connection Error/Fail
- Quarkus - ContextNotActiveException when injecting a request scoped bean in Interceptor
- Request-scoped bean is available in @RestController but throws ScopeNotActiveException in HttpFilter
- @RequestScope vs ThreadLocal for mutlti tenant in Quarkus with Mutiny?
- Springboot | RequestScope | @Async | Is their any way to identify that request is executing through Async thread OR main thread?
- NestJS ModuleRef instances
- How does RequestScope in Quarkus/CDI work?
- How to use request scoped bean in a reactor framework async call?
- Converting Request scoped bean to JSON string
- Is it able to inject RequestScope bean into Singleton bean using Constructor Injection in Spring?
- Spring Boot: Unable to access the request scope bean in Spring Scheduler
- Spring Boot Request Scoped Bean
- Cookie set in web filter is not available in request bean
- How can I get the value of an object inside an object by requestscope?
- micronaut @RequestScope - not creating bean per incoming http-request
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
awaitcan cause thread jumps, so thread static variables will naturally cause problems.To work around this, you can either use
AsyncLocal<T>(available in .NET 4.6), or (if you must)HttpContext.Current.Items. Of those two, I would definitely recommendAsyncLocal<T>overItems, if it's available on your platform.