Is this OK?

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Stevie_mac (no.email_at_please.com)
Date: 04/08/04


Date: Thu, 8 Apr 2004 18:31:38 +0100

Hi all, quick question - I need a bit of clarity.

If I have a public class with only Public Shared functions in it, in an APS.NET web app (for common procedures) is it
safe (since multiple web pages, can at any time access the code within)

The reason for a Shared class like this is that, it would contain all of the useful functions we put together over time
like FillList, SelectListItem, FindLastItemInList, EmptyList, SortList etc etc etc

Example below - a simple routine that fills a dropdownlist. Would it be safe being accessed at multiple times by
the APSX pages? Forget the fact the code might not be perfect - only that I would like to arrange my code this way.

I suspect there may be caveats - but I need a more knowledgeable opinion.

Public Class MyUtils
    Public Shared Function FillList(ByVal objList As DropDownList, ByVal sSql As String, ByVal sConnection As String) As
Boolean
        Dim dr As OleDb.OleDbDataReader, Li As ListItem
        Dim cn As New OleDb.OleDbConnection(sConnection)
        Dim cmd As OleDb.OleDbCommand
        Try
            cn.Open()
            cmd = New OleDb.OleDbCommand(sSql, cn)
            dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
            While dr.Read
                Li = New ListItem
                Li.Text = dr(0)
                Li.Value = dr(1)
                objList.Items.Add(Li)
            End While
        Catch ex As Exception
            Stop
            Return False
        Finally
            cmd.Dispose()
            If dr Is Nothing = False Then dr.Close()
            cn.Close()
        End Try
        Return True
    End Function

    Public Function EmptyList(...)
        ...
    End Function

    ...
    ...
    'Other Public Shared Functions...
    ...
    ...
End Class

Usage...
    FillList(cmbListOfNames, AppSettings("SQL.PEOPLE"),AppSettings("CONSTRING.MANAGEMENT"))



Relevant Pages

  • Is shared safe in this example?
    ... If I have a public class with only Public Shared functions in it, in an APS.NET web app is it ... safe (since multiple web pages, can at any time access the code within) ... Would it be safe being accessed at multiple times by ...
    (microsoft.public.dotnet.languages.vb)
  • RE: C# Override limitation..why?
    ... > Why does the signature of the override have to match exactly the base ... > It seems like a perfectly safe thing to do so why can't I do it? ... Prev by Date: ...
    (microsoft.public.dotnet.languages.csharp)