Hi,
I have a program need to P/Invoke a Shared Object API from a C# thread in
Mono , but I am always meet the "seg fault" error.
My code like below:
class MainClass
{
private static void ThreadRun()
{
XmlConfigurator.Configure(new
FileInfo(AppDomain.CurrentDomain.SetupInformation.ApplicationBase +
"Log4Net.config"));
Console.WriteLine("Hello Test!");
HDDDriver DD;
DD=new HDDDriver(100);
Byte[] TT=new Byte[1880000*6];
DD.InitOutputPort(0,38000000);
int i=0;
while(i<1000)
{
DD.OutputBuffer(0,TT);
i++;
}
DD.UnloadOutputPort(0);
Console.WriteLine("End");
}
static string RL()
{
return Console.ReadLine();
}
static void WL(object aMsg)
{
Console.WriteLine(aMsg);
}
static void W(object aMsg)
{
Console.Write(aMsg);
}
public static void Main(string[] args)
{
Thread FThread =new Thread(new ThreadStart(ThreadRun));
FThread.Start();
String tmpStr = RL();
while (tmpStr.ToUpper() != "QUIT")
{
tmpStr = RL();
}
FThread.Abort();
}
}
But when I changed the code to no thread, the code can run ok,like this:
class MainClass
{
private static void ThreadRun()
{
XmlConfigurator.Configure(new
FileInfo(AppDomain.CurrentDomain.SetupInformation.ApplicationBase +
"Log4Net.config"));
Console.WriteLine("Hello Test!");
HDDDriver DD;
DD=new HDDDriver(100);
Byte[] TT=new Byte[1880000*6];
DD.InitOutputPort(0,38000000);
int i=0;
while(i<1000)
{
DD.OutputBuffer(0,TT);
i++;
}
DD.UnloadOutputPort(0);
Console.WriteLine("End");
}
static string RL()
{
return Console.ReadLine();
}
static void WL(object aMsg)
{
Console.WriteLine(aMsg);
}
static void W(object aMsg)
{
Console.Write(aMsg);
}
public static void Main(string[] args)
{
ThreadRun();
}
}
Would someone could help me ?
_______________________________________________
Mono-list maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list