MaxScript里开不了线程,但是可以用.Net的BackgroundWorker来做后台处理

BackgroundWorker
Fn BackgroundTcpListenerDoWork theSender theEvent = 
(
IPAddress
= DotNetClass "System.Net.IPAddress"
theIPAddress
= IPAddress.Parse "127.0.0.1"
theTcpListener
= DotNetObject "System.Net.Sockets.TcpListener" theIPAddress 7457
theTcpListener.Start()

while not theSender.CancellationPending do
(
theSocket
= theTcpListener.AcceptSocket()
theByteStream
= DotNetObject "System.Byte[]" 8192
theSocket.Receive theByteStream
Encoding
= DotnetClass "System.Text.Encoding"
theString
= Encoding.UTF8.GetString(theByteStream)
if not theSender.CancellationPending do Execute theString
)
theTcpListener.Stop()
)

BackgroundWorker
= DotNetObject "System.ComponentModel.BackgroundWorker"
DotNet.AddEventHandler BackgroundWorker
"DoWork" BackgroundTcpListenerDoWork
BackgroundWorker.WorkerSupportsCancellation
= true
BackgroundWorker.RunWorkerAsync()


/*
BackgroundWorker.CancelAsync()
BackgroundWorker.Dispose()
*/

  

相关文章:

  • 2021-12-29
  • 2021-09-22
  • 2022-01-16
  • 2021-06-30
  • 2022-01-18
  • 2021-07-26
  • 2021-12-31
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-31
  • 2021-11-04
  • 2022-01-10
  • 2021-07-20
  • 2021-10-26
  • 2021-12-02
相关资源
相似解决方案