我正在研究一个项目,该项目必须同时监视多个RFID阅读器。 RFID阅读器有一个DLL文件,它公开了与之交互的方法。一种方法是打开一个连接。当我调用静态DLL连接到一个RFID阅读器时,它工作正常。如果我运行我的应用程序的多个实例,他们都会调用静态DLL并连接到不同的RFID阅读器。不过,我需要仅运行主应用程序的单个实例,然后将单个线程连接到单个RFID阅读器。但是当我这样做时,第一个连接是成功的,但任何其他线程都无法调用该DLL,因为我认为它在共享内存空间中,因此被第一个线程占用。我怎么解决这个问题?从多个线程调用RFID阅读器的静态DLL
这里是DoWork的温控功能是由Thread.Start
public void DoWork()
{
__parent.UpdateLog(ReaderIP + ": working.");
int openresult = 0;
int frmcomportindex = 0;
int fOpenComIndex;
byte fComAdr = Convert.ToByte("FF", 16); // $FF
//this line works fine for the first thread adn fails for all following threads
// but works fine if I run multiple instances of my app and get each to connect to a single RFID reader
openresult = StaticClassReaderB.OpenNetPort(ReaderPort, ReaderIP, ref fComAdr, ref frmcomportindex);
fOpenComIndex = frmcomportindex;
退房这一个:https://msdn.microsoft.com/en-us/library/system.threading.thread.beginthreadaffinity(v=vs.110).aspx – Fruchtzwerg