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

Popular posts from this blog

Is there an open source WebSockets (JavaScript) XMPP library? -

java - Is there an object like a "Set" that can contain only unique string values, but also contain a count on the number of occurrences of the string value? -

iphone - How do I make a UIPickerView in a UIActionSheet -