码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2016-06-01 23:15:42      阅读:434      评论:0      收藏:0      [点我收藏+]

标签:

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() */

 

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

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

标签:

原文地址:http://www.cnblogs.com/lged/p/5551351.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!