在Jscript中实例化一个System.Threading.Thread对象 [英] Instantiating a System.Threading.Thread object in Jscript

查看:211
本文介绍了在Jscript中实例化一个System.Threading.Thread对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to create a new System.Threading.Thread object using Jscript, but I can't get the constructor to work. If I just do the following,

var thread = new Thread( threadFunc );

function threadFunc() {
    // do stuff
}

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

但是,如果我尝试强制threadFunc到System.Threading.ThreadStart通过

However, if I try to coerce threadFunc to System.Threading.ThreadStart via

var thread = new Thread( ThreadStart(threadFunc) )

我收到错误 JS1208:指定的转换或胁迫是不可能的

任何人都知道如何做到这一点?

Anyone know how to do this? It seems like it should be trivial.

推荐答案

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

Wrap it in a class, it should work.

import System;
import System.Threading;

class MyClass {
    static function threadFunc() { Console.WriteLine("threadFunc"); }
}

var thread = new Thread( ThreadStart(MyClass.threadFunc) );
thread.Start();
thread.Join();

这篇关于在Jscript中实例化一个System.Threading.Thread对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆