Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
IronPython在C#回调函数中返回重复值_C#_Python_.net_Callback_Ironpython - Fatal编程技术网

IronPython在C#回调函数中返回重复值

IronPython在C#回调函数中返回重复值,c#,python,.net,callback,ironpython,C#,Python,.net,Callback,Ironpython,在名为test.py的文件中,我有以下代码: def foo(回调): 回调(1、2、3) def条(x、y、z): 打印x,y,z 当在IronPython控制台中执行foo(bar)时,它会输出: 123 我想从C应用程序调用foo()。下面的C#代码执行foo(),并向其传递一个C#回调函数 var-engine=Python.CreateEngine(); 动态范围=engine.CreateScope(); engine.ExecuteFile(“test.py”,范围); sco

在名为
test.py
的文件中,我有以下代码:

def foo(回调):
回调(1、2、3)
def条(x、y、z):
打印x,y,z
当在IronPython控制台中执行
foo(bar)
时,它会输出:

123
我想从C应用程序调用
foo()
。下面的C#代码执行
foo()
,并向其传递一个C#回调函数

var-engine=Python.CreateEngine();
动态范围=engine.CreateScope();
engine.ExecuteFile(“test.py”,范围);
scope.callbackFunction=新操作
((x,y,z)=>Debug.Print(“{0}\t{1}\t{2}”,x,y,z));
scope.foo(scope.callbackFunction);
输出为:

1
我不明白为什么
x==z
。为什么C#输出是
1 2 1
而不是
1 2 3
?我是否错误地发送了一个C#回调函数


我在Windows 7上运行这个程序,C#应用程序的目标是.NET 4.5,我的IronPython版本是2.7.4。

除了一个打字错误,我想不出发生这种情况的原因。这就是您正在使用的代码吗?我已经在4.5.1和IronPython 2.7.5b2中尝试过了,我无法重现这个问题。我也无法重现这个问题。我重新编译并运行了大约10次程序,没有更改任何代码。前六次我遇到了这个错误。过去四次(从那时起)这个问题不再发生。我想有一个更深层次的bug在起作用,但我怀疑我是否能找到它是什么。