asp.net使用 multithread的問題

cheong 2003-07-25 10:03:33
asp.net 可否使用multithread,
使用方法是 ?

可否使用multithread 在 server中 同時open 多個word ???
...全文
49 9 打赏 收藏 举报
写回复
9 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
nyleex2000 2003-08-29
  • 打赏
  • 举报
回复
一段多线程的例子:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'//make sure the user has entered proper data
'//by relying on the Page.IsValid method which will
'//return false if the user hasn't entered the proper data
If (Page.IsValid = True) Then

'//create a new thread and point it at the
'//generate prime numbers method
Dim NewThread As Thread = New Thread(AddressOf GeneratePrimeNumbers)

'//set the thread priority to something
'//that is acceptable, warning setting the priority
'//to normal or higher will potentially lock up your server,
'//or make your asp.net pages respond very slowly. The best
'//priority to use is lowest
NewThread.Priority = ThreadPriority.Lowest

'//start the new thread running
NewThread.Start()

'//redirect the user to the response page
'//while the thread is working
Response.Redirect("/multithreaded/results1.aspx")
End If

End Sub

Public Sub GeneratePrimeNumbers()

'//create an XmlDocument that we can store our results in
'//and we'll save this information to a session variable when
'//we are done
Dim Results As XmlDocument = New XmlDocument()
Dim Node1 As XmlNode = Results.CreateElement("PrimeNumbers")
Results.AppendChild(Node1)

'//lock the session variable collection so that it
'//thread safety is assurred
SyncLock Session.SyncRoot
Session("Results") = Results.InnerXml
End SyncLock

'//create counter that we use to look through
'//as we move from min to max value looking for
'//prime numbers
Dim Counter As Integer

'//create a for-next looping control structure.
'//we go through each number from min to max looking to see
'//if it is a prime number
For Counter = Convert.ToInt32(MinValue.Text) To Convert.ToInt32(MaxValue.Text) Step 1

'//create a boolean variable and set it to true
'//if we find that the number isn't prime, then we set this to false
Dim prime As Boolean = True

'//create second count. We'll go through and divide counter
'//by each of these numbers. If there isn't a remainder, then
'//the number isn't prime.
Dim Counter2 As Integer

'//This is the second control structure. we start at 2 and move up to the
'//value of counter. During each interation, we divide Counter by Counter2
'//if the operation doesn't return a remainder, then the number isn't prime.
For Counter2 = 2 To (Counter - 1) Step 1
'//here's where we do the dividing. If no remainder, then we simply
'//set the value of the prime variable to false
If (Counter Mod Counter2 = 0) Then
prime = False
End If
Next

If prime = True Then
'//add our prime number to our xml document
'//so that the number can be returned
Dim node2 As XmlNode = Results.CreateElement("Number")
node2.InnerText = Counter
Results.DocumentElement.AppendChild(node2)

'//show update the results session variable
'//provided that the user has selected to show
'//partial results
If (ShowPartial.Checked = True) Then

'//again, lock the session object so that
'//thread safety is assurred
SyncLock Session.SyncRoot
Session("Results") = Results.InnerXml
End SyncLock
End If

End If

Next

'//update the session variable with the final results
'//locking the object first
SyncLock Session.SyncRoot
Session("Results") = Results.InnerXml

'//set the session finished variable to true
'//which indicates that the second thread has completed it's work
Session("Finished") = True
End SyncLock


End Sub
cheong 2003-08-29
  • 打赏
  • 举报
回复
>>>可否使用multithread 在 server中 同時open 多個word ???
suppose so, but why do you want to do that? msword is very resource extensive

因為個server 是 multi-task, 多個user 會 open 各自已的word
standy 2003-08-25
  • 打赏
  • 举报
回复
真是高难动作
saucer 2003-08-24
  • 打赏
  • 举报
回复
>>>asp.net 可否使用multithread

yes, see an example
Boost Web Performance With Multithreading
http://www.fawcette.com/vsm/2002_11/magazine/features/chester/

>>>可否使用multithread 在 server中 同時open 多個word ???
suppose so, but why do you want to do that? msword is very resource extensive
Oldman 2003-08-23
  • 打赏
  • 举报
回复
可以,但是不知道怎麼設置權限!
shenlongju 2003-07-25
  • 打赏
  • 举报
回复
up
SunLightIce 2003-07-25
  • 打赏
  • 举报
回复
multithread??????
在 server中 同時open 多個word??????
关注ing
greystar 2003-07-25
  • 打赏
  • 举报
回复
gz
  • 打赏
  • 举报
回复
关注!帮你UP!
发帖
.NET社区

6.1w+

社区成员

.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
帖子事件
创建了帖子
2003-07-25 10:03
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。