【转】MaxScript.Net接收本地端口的消息执行

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
theTcpListener.Start() while not theSender.CancellationPending do
(
theSocket = theTcpListener.AcceptSocket()
theByteStream = DotNetObject "System.Byte[]"
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()
*/

【转】http://www.xuebuyuan.com/429604.html

上一篇:asp.net MVC 框架中控制器里使用Newtonsoft.Json对前端传过来的字符串进行解析


下一篇:python27+django数据库配置常见问题