zoukankan      html  css  js  c++  java
  • 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 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()
    */

      

  • 相关阅读:
    Completely disable mousewheel on a WinForm
    C# Form内存回收
    解锁用户
    CentOS7+JDK8编译Hadoop2.6.4
    网址收藏
    pvresize
    Linux crontab 命令格式与详细例子
    在CentOS 7中安装与配置JDK8
    Disable SELinux CentOS 7
    Python3标准库:math数学函数
  • 原文地址:https://www.cnblogs.com/sitt/p/2160609.html
Copyright © 2011-2022 走看看