Solid ASP.NET Threading examples?
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngvb' list.


Walter Quesada
-- Moved from [aspngfreeforall] to [aspngvb] by Tim Musschoot <Click here to reveal e-mail address> --

I can't for the life of me find any solid ASP.NET multithreading examples, everything is Windows Forms in C# which I tried to recreate on web forms, but to no success. Anybody out there have any solid asp.net multithreading (System.Threading) examples?

What I am basically trying to do is create a background process (in dll file) launched by a web form's button onclick event ... I want the user to click the button and get a response under a second saying they will be notified via email when the process has been completed.

Your help is greatly appreciated!!

Walter

PS: Here's a little something I modified that I found in MSDN, it's not working for me though. The page runs fine, but after the alloted time frame, nothing happens (running Test.OnNewThread), the XML file never gets updated. If I run the same script without the threading (directly running App.Main), the XML file does indeed get updated, so I am sure it has something to do with the threading, let me know what you think ...

Imports System
Imports System.Xml
Imports System.Threading
Namespace Test
Class TimerExampleState
Public counter As Integer = 0
Public tmr As Timer
End Class
Public Class OnNewThread
Public Shared Sub Start()
Dim oThreadExample As New App()
Dim oThreadStart As New ThreadStart(AddressOf oThreadExample.Main)
Dim oThread As New Thread(oThreadStart)
oThread.Start
End Sub
End Class
Public Class App
Public Shared Sub Main()
Dim s As New TimerExampleState()
Dim timerDelegate As New TimerCallback(AddressOf CheckStatus)
Dim timer As New Timer(timerDelegate, s, 240000, 1000)
s.tmr = timer
While Not (s.tmr Is Nothing)
Thread.Sleep(0)
End While
WriteXmlTest()
End Sub
Shared Sub CheckStatus(state As [Object])
Dim s As TimerExampleState = CType(state, TimerExampleState)
s.counter += 1
If s.counter = 5 Then
s.tmr.Change(10000, 100)
End If
If s.counter = 10 Then
s.tmr.Dispose()
s.tmr = Nothing
End If
End Sub
Public Shared Sub WriteXmlTest()
Dim strXml As String = "mytestxmlfile"
Dim objXML As XmlDocument = New XmlDocument()
objXML.Load(strXML)
Dim objTests As XmlNode = objXML.SelectSingleNode("tests")
Dim objTest As XmlElement = objXML.createElement("test")
Dim objDate As XmlAttribute = objXML.CreateAttribute("date")
objDate.Value = DateTime.Now()
objTest.SetAttributeNode(objDate)
objDate = Nothing
Dim objUid As XmlAttribute = objXML.CreateAttribute("msg")
objUid.Value = "MultiThread Testing!"
objTest.SetAttributeNode(objUid)
objUid = Nothing
objTests.appendChild (objTest)
objXML.Save(strXML)
objTest = Nothing
objTests = Nothing
objXML = Nothing
End Sub
End Class
End Namespace

Reply to this message...
 
    
Richard Purchas
Check the presentations out at: http://www.sdnug.org. I think there's one
(with source) on using threading.

[Original message clipped]

Reply to this message...
 
    
Bob Macleod
Please be a bit more specific. The reference below does not lead cleanly to
any information on using threading. Thanks

[Original message clipped]

_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com

Reply to this message...
 
 
System.DateTime
System.Threading.Thread
System.Threading.ThreadStart
System.Threading.TimerCallback
System.Xml.XmlAttribute
System.Xml.XmlDocument
System.Xml.XmlElement
System.Xml.XmlNode




Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
 
 Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us - Terms of Use - Privacy Policy - www.dotnet247.com