首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

关于非托管 冲突有关问题

2012-02-04 
关于非托管 冲突问题下面就是我调用的非托管代码块:[DllImport(DtPlayDll.dll)]private static extern i

关于非托管 冲突问题
下面就是我调用的非托管代码块: 
[DllImport("DtPlayDll.dll")] 
  private static extern int Func(double alltime, double ctime, string[] b); 

class a{

a()
{
Func(alltime,ctime,b);
}

}
我再将这个段代码写成一个DLL,当多个线程调用这个类中的构造函数,有冲突的可能性吗?

[解决办法]
private static extern int Func(double alltime, double ctime, string[] b); 
托管代码的声明函数都应该是public的把
 public static extern int Func(double alltime, double ctime, string[] b); 


至于调用,建议你在每个类中声明,然后调用

[解决办法]
class a{ 
static object flag = new object();
a() 

lock(flag){
Func(alltime,ctime,b); 
}




[解决办法]

引用楼主 pen546 的帖子:
下面就是我调用的非托管代码块:
[DllImport("DtPlayDll.dll")]
private static extern int Func(double alltime, double ctime, string[] b);

class a{

a()
{
Func(alltime,ctime,b);
}

}
我再将这个段代码写成一个DLL,当多个线程调用这个类中的构造函数,有冲突的可能性吗?

热点排行