【问题标题】:Instantiating a System.Threading.Thread object in Jscript在 Jscript 中实例化 System.Threading.Thread 对象
【发布时间】:2010-03-19 01:35:05
【问题描述】:

我正在尝试使用 Jscript 创建一个新的 System.Threading.Thread 对象,但我无法让构造函数工作。如果我只是执行以下操作,

var thread = new Thread( threadFunc );

function threadFunc() {
    // do stuff
}

然后我得到错误JS1184:多个构造函数匹配这个参数列表。

但是,如果我尝试将 threadFunc 强制转换为 System.Threading.ThreadStart

var thread = new Thread( ThreadStart(threadFunc) )

我得到错误JS1208:指定的转换或强制是不可能的

有人知道怎么做吗?看起来应该是微不足道的。

【问题讨论】:

    标签: .net multithreading delegates javascript


    【解决方案1】:

    将它包装在一个类中,它应该可以工作。

    import System;
    import System.Threading;
    
    class MyClass {
        static function threadFunc() { Console.WriteLine("threadFunc"); }
    }
    
    var thread = new Thread( ThreadStart(MyClass.threadFunc) );
    thread.Start();
    thread.Join();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多