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

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -