You're problem isn't thread safe so much as it isn't "session" safe. 
Shared objects should not be used for this purpose.

The simple way to do this is store the array in a session variable
that you update when the user adds things to the list.  Session
variables unique to the user and you won't have this issue.

Kill the shared variable and
Add a property to the form to encapsulate access to the session variable

Private ReadOnly Property InputList as ArrayList
     Get
           Dim al as ArrayList
           'retrieve the list if it exists
           if Not IsNothing(Session("InputList")) then
               al = Session("InputList")
           else
               'otherwise create a new one.
               al = new ArrayList
              Session.Add("InputList", al)
           end if
          return al


    End Get
End Property

The only other thing you will possible want to do is clear the session
variable when the user leaves the page and comes back.  In which case
you will want to add this to your Page_load event

If Not Page.IsPostBack Then
     InputFile.Clear()
End if


On 12/21/05, denkide <[EMAIL PROTECTED]> wrote:
> I have an app with a file uploaded that will allow the user to add
> multiple files to a listbox, then will upload all files to the server
> in a batch.
>
> To do this i have a Public Shared ArrayList at the top of the page to
> store the HTMLInputFile objects in.
>
> The problem is that since it is shared, whenever another user is on
> the site at the same time, the threads get corrupted.
>
> Is there another way that i can change this around to make it thread
> safe?
>
> I have created a class to take the place of the Public Shared
> ArrayList, but cannot put it into Viewstate since it holds
> HTMLInputFiles (which is what is stored in the arraylist so that they
> can be uploaded in batch).
>
> Any help would be great. I thought i had this thing done until two of
> us were testing at the same time and we found this big old error.
>
> code is below:
> _____________________________
>
> Public Class UpdateForm
>       Public Shared InputFile As ArrayList = New ArrayList
>
>       Private Sub btnAddFile_Click(ByVal sender As System.Object,
> ByVal e As System.EventArgs) Handles btnAddFile.Click
>
>         ....
>
>         lbFileList.Items.Add(FindFile.PostedFile.FileName)
>         InputFile.Add(FindFile)
>
>
>       End Sub
>
>       Private Sub btnRemove_Click(ByVal sender As System.Object,
> ByVal e As System.EventArgs) Handles btnRemove.Click
>
>          InputFile.RemoveAt(lbFileList.SelectedIndex)
>          lbFileList.Items.Remove(lbFileList.SelectedItem.Text)
>
>       End Sub
>
>       Private Sub btnSubmit_Click(ByVal sender As System.Object,
> ByVal e As System.EventArgs) Handles btnSubmit.Click
>
>          Dim File As System.Web.UI.HtmlControls.HtmlInputFile
>
>         For Each File In InputFile
>            Dim fn As String = System.IO.Path.GetFileName
> (File.PostedFile.FileName)
>            File.PostedFile.SaveAs(ConfigurationSettings.AppSettings
> ("BASE_PATH") + sStoragePath + "\" + fn)
>            Response.Flush()
>
>         Next
>
>         InputFile.Clear()
>         lbFileList.Items.Clear()
>       End Sub
>
>
> End class
>
>
>
>
>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>


--
Dean Fiala
Very Practical Software, Inc
http://www.vpsw.com


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/KIlPFB/vlQLAA/TtwFAA/saFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to