开发者

ASP.NET Web Service + Module + Public variable = thread safe?

In my ASP.NET Web Service I've included a module in which their are Public declared variables. Will they be thread-safe? Will they get mixed up upon simultaneous calls?

Those variables are mostly DatsSet, DataTable and SQLDataAdapter..

Partial code of the module:


Imports System.Data.OleDb
Imports System.Diagnostics

Module modCommon

    Public bDoLog As Boolean
    Public sCurrentODBC As String
    Public cn As SqlConnection
    Public Query1ds As DataSet
    Public Query1 As DataTable
    Public Query1adapter As SqlDataAdapter

@scripni

Thanks, as I'm not familiary with your suggestions, I will move everything locally.

Additionally, will the following variables be thread-safe?:


[ToolboxItem(False)]_
Public Class Service1 
     Inherits System.Web.Services.WebService 

     Dim sName As String 
     Dim sCurrentPath As String 

     [WebMethod()]_
     Public Function Capture(ByVal sPath As String) As String 
          sName = "Joe"
     E开发者_如何学编程nd Function 
End Class 


If you're using web services than yes, you will have concurency problems when multiple services will try to access the same resource, and SqlConnection is definetly a resource you don't want shared.

You should make sure that you don't have simultaneous calls to the properties (for ex. by wrapping the fields with getters / setters and implementing locks in those methods) or by moving the code to a class and instantiating that class whenever you need it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜