Web thread loading from dbase

Hi All,

I’m trying to move the following method into a thread,
but wonder how to pass the sessions database to the thread, and the thread to fill the sessions poster array;

Dim imagesRS As RecordSet
imagesRS = Session.Orders.Findimages // get the recordset with the images from the sessions sqlite database

If imagesRS <> Nil Then
For i As Integer = 1 To imagesRS.RecordCount
Session.ImageList(i) = imagesRS.Field(“Name”).StringValue
dim temp as Picture
temp = ImagesRS.Field(“Blob”).PictureValue
Session.poster(i) = temp


End If

I tried placing above code in the run event of a thread, but obviously needs a way to link to the sessions properties.

Subclass Thread and add a WeakRef property pointing to the Session itself. I’d suggest using a Computed Property and have it do all the heavy lifting for you:

[code]MySession as Session
mMySession = new weakref(value)

If mMySession = Nil or mMySession.Value = Nil then
Return Nil
Return Session(mMySession)
End If

Then in your thread code,

dim s as session = MySession

But only when you need it. Let the variable go out of scope as soon as you are done with it, and always check to see if it is Nil.

The advantage to doing it this way is that if the session ends, your thread doesn’t keep it in existence when the thread itself is not actually doing anything. If the session user happens to disconnect, everything will still clean up nicely.

@Greg O’Lone

Thanks for the rapid reply Greg. Due to my inexperience with threads, I’m somewhat at a loss on where to place what;
I’ve added a CustomThread with a computed property MySession.
The Get and Set are entered as listed above, but on compilation I get two errors;

CustomThread.mMySession.Get, line 1

This item does not exist
if mMySession = Nil or mMySession.value = nil then

and the second error;

CustomThread.mMySession.Set, line 1

Type mismatch error. Expected Session.Session, but got WeakRef
mMySession = new weaker(value)

I’m sure I’m doing something wrong, but don’t quite know what.

You need to change the backing property to type WeakRef.

mMySession as WeakRef