c# - Are static methods in ASP.NET code-behind classes non-thread-safe? -
Do I use the static
methods in my ASP.NET page
Can I and UserControls
class if they do not use members of any instance? I.e .:
Protected Zero GridviewviewExanging (Object Sender, GridviewEventErgus E) {gridStatement.DataSource = CreateDataSource (); Gridstation.pageindex = e. Nupez Index; GridStatement.DataBind (); } Private static datatable CreateDataSource () {(var command = New SqlCommand (using "SELECT foobar")) {var table = New DataTable (); New SqlDataAdapter (Command). Fill (table); Return table; }}
Or is not this thread-safe?
Yes, you can use a static member - they are thread-protected. Each thread is a different one Will be executed in context and therefore any object created inside a static method will only relate to that thread.
You only need to worry if a steady method is reaching the fixed field, such as the list. But the code in your example is definitely safe to thread.
Comments
Post a Comment