|
-
Jan 11th, 2005, 04:11 AM
#1
Thread Starter
Hyperactive Member
Is this a BUG or am I missing summat?
Hi all,
The code below creates a class object that sources events. It then caches the object so on the next request it can retrieve it.
Problem is the event it raises runs multiple times (first time round is fine). For every time its cached and retrieved its like it stores the event again.
If you debug through, you can see that RaiseEvent is only called once, however the event WILL repeat several times. See the debugger window for output.
I _think_ this is all you need. I've cut this down from a very large chunk of code.
Paste all this into a webform called "Test1.aspx", you will need a PlaceHolder called phMain on the form.
VB Code:
Public Class TestClass
Private m_Value As Long
Event TestEvent()
Sub New(ByVal Value As Long)
m_Value = Value
End Sub
Public Function PubFunc() As Control
RaiseEvent TestEvent()
Return New LiteralControl(CStr(m_Value))
End Function
End Class
Public Class Test1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
Protected WithEvents phMain As System.Web.UI.WebControls.PlaceHolder
#End Region
Protected WithEvents TestObj As TestClass
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Retrieve from Cache
TestObj = CType(HttpContext.Current.Cache("TestObj" & HttpContext.Current.Session.SessionID), TestClass)
If TestObj Is Nothing Then
'Not in Cache so create the object
TestObj = New TestClass(123456)
'Save the Object in the Cache
HttpContext.Current.Cache.Insert("TestObj" & HttpContext.Current.Session.SessionID, TestObj)
End If
'Call a function of the Obj to get HTML output
phMain.Controls.Add(TestObj.PubFunc)
End Sub
Private Sub TestObj_TestEvent() Handles TestObj.TestEvent
System.Diagnostics.Debug.Write("Event Running " & Now & vbCrLf)
Try
Response.Write("Event Running")
Catch
'Response only seems to be available
'for a single instance of the event?
Finally
End Try
End Sub
End Class
Last edited by tailz; Jan 12th, 2005 at 02:23 PM.
-
Jan 11th, 2005, 04:16 AM
#2
Thread Starter
Hyperactive Member
Re: Is this a BUG or am I missing summat?
I've been working on this for HOURS, the minute I post I solved it.
At the bottom of Page_Load I added........
......and it all went away. In vb6 I was religious with clearing up objects.... guess I still should be
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|