P
Pradnya Patil
hi ,
I am trying to draw ' html div-tag ' on the screen which will
resemble a rectangle through vb.net code.
I want it to be drawn faster...so I introduced multithreading
using Threadpool. I divided the complete drawing into 3 parts..1st will
be done by main thread and other two are done in these procedures -
<1> LongTimeTask
<2> LongTimeTask2
I have invoked the threads using below method.
**************
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf
LongTimeTask), "hi")
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf
LongTimeTask2), "hi"
**************
Now ,the problem is...sometimes I can't see the html generated
by the functions LongTimeTask and LongTimeTask2.
While debugging, I have observed that these procedures
sometimes execute after Page_load is completely executed.
Can anybody identify where the problem is ? I am just exploring
multithreading and don't know in depth abt it .Am i missing some code
for multithreading ?
Any help will be appreciated.
This is the code:
'---------------------------------------------------------------------------------------------------
Imports System.Threading
Partial Class TestSpdThreadPool
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
MainFun()
End Sub
Public Sub MainFun()
Dim intCnt2 As Integer
Dim intB As Integer = 0
Dim strb As New StringBuilder
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf
LongTimeTask), "hi")
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf
LongTimeTask2), "hi")
For intCnt2 = 0 To 10000 Step 40
If intB = 500 Then
Me.Form.InnerHtml &= strb.ToString
strb.Remove(0, strb.Length)
intB = 0
End If
strb.Append(" <div style='width: 6px; height:6px;
background-color: transparent; z-index: 1;left: " & intCnt2 & "px;
position: absolute; top: " & 100 & "px;'><b>M</b></div>")
Next
Me.Form.InnerHtml &= strb.ToString
End Sub
Public Sub LongTimeTask(ByVal str As Object)
'Thread.Sleep(100)
Dim intCnt3 As Integer
Dim intB3 As Integer
Dim strb As New StringBuilder
For intCnt3 = 0 To 10000 Step 40
If intB3 = 500 Then
Me.Form.InnerHtml &= strb.ToString
strb.Remove(0, strb.Length)
intB3 = 0
End If
strb.Append("<div style='width: 6px; height: 40px;
background-color: red; z-index: 2;left: " & intCnt3 + 500 & "px;
position: absolute; top: " & 200 & "px;'><b>T----------P</b></div>")
'strb.Append("thread 1 ----->")
Next
Me.Form.InnerHtml &= strb.ToString
End Sub
Public Sub LongTimeTask2(ByVal str As Object)
Dim intCnt3 As Integer
Dim intB3 As Integer
Dim strb As New StringBuilder
'Thread.Sleep(100)
For intCnt3 = 0 To 10000 Step 40
If intB3 = 500 Then
Me.Form.InnerHtml &= strb.ToString
strb.Remove(0, strb.Length)
intB3 = 0
End If
strb.Append("<div style='width: 6px; height: 40px;
background-color: blue; z-index: 2;left: " & intCnt3 + 10 & "px;
position: absolute; top: " & 300 & "px;'><b>T----------P</b></div>")
'strb.Append("thread 1 ----->")
Next
Me.Form.InnerHtml &= strb.ToString
End Sub
End Class
'---------------------------------------------------------------------------------------------------
I am trying to draw ' html div-tag ' on the screen which will
resemble a rectangle through vb.net code.
I want it to be drawn faster...so I introduced multithreading
using Threadpool. I divided the complete drawing into 3 parts..1st will
be done by main thread and other two are done in these procedures -
<1> LongTimeTask
<2> LongTimeTask2
I have invoked the threads using below method.
**************
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf
LongTimeTask), "hi")
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf
LongTimeTask2), "hi"
**************
Now ,the problem is...sometimes I can't see the html generated
by the functions LongTimeTask and LongTimeTask2.
While debugging, I have observed that these procedures
sometimes execute after Page_load is completely executed.
Can anybody identify where the problem is ? I am just exploring
multithreading and don't know in depth abt it .Am i missing some code
for multithreading ?
Any help will be appreciated.
This is the code:
'---------------------------------------------------------------------------------------------------
Imports System.Threading
Partial Class TestSpdThreadPool
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
MainFun()
End Sub
Public Sub MainFun()
Dim intCnt2 As Integer
Dim intB As Integer = 0
Dim strb As New StringBuilder
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf
LongTimeTask), "hi")
ThreadPool.QueueUserWorkItem(New WaitCallback(AddressOf
LongTimeTask2), "hi")
For intCnt2 = 0 To 10000 Step 40
If intB = 500 Then
Me.Form.InnerHtml &= strb.ToString
strb.Remove(0, strb.Length)
intB = 0
End If
strb.Append(" <div style='width: 6px; height:6px;
background-color: transparent; z-index: 1;left: " & intCnt2 & "px;
position: absolute; top: " & 100 & "px;'><b>M</b></div>")
Next
Me.Form.InnerHtml &= strb.ToString
End Sub
Public Sub LongTimeTask(ByVal str As Object)
'Thread.Sleep(100)
Dim intCnt3 As Integer
Dim intB3 As Integer
Dim strb As New StringBuilder
For intCnt3 = 0 To 10000 Step 40
If intB3 = 500 Then
Me.Form.InnerHtml &= strb.ToString
strb.Remove(0, strb.Length)
intB3 = 0
End If
strb.Append("<div style='width: 6px; height: 40px;
background-color: red; z-index: 2;left: " & intCnt3 + 500 & "px;
position: absolute; top: " & 200 & "px;'><b>T----------P</b></div>")
'strb.Append("thread 1 ----->")
Next
Me.Form.InnerHtml &= strb.ToString
End Sub
Public Sub LongTimeTask2(ByVal str As Object)
Dim intCnt3 As Integer
Dim intB3 As Integer
Dim strb As New StringBuilder
'Thread.Sleep(100)
For intCnt3 = 0 To 10000 Step 40
If intB3 = 500 Then
Me.Form.InnerHtml &= strb.ToString
strb.Remove(0, strb.Length)
intB3 = 0
End If
strb.Append("<div style='width: 6px; height: 40px;
background-color: blue; z-index: 2;left: " & intCnt3 + 10 & "px;
position: absolute; top: " & 300 & "px;'><b>T----------P</b></div>")
'strb.Append("thread 1 ----->")
Next
Me.Form.InnerHtml &= strb.ToString
End Sub
End Class
'---------------------------------------------------------------------------------------------------