I'm developing software using FANUC Robot Interface DLL. The DLL contains a type DataTable
which needs to be refreshed (by calling DataTable.Refresh()
) every 20ms to acquire new data from the robot. I need to do this on a different thread but the main thread, so I created a BackgroundWorker
to call the Refresh()
method.
On the PC (PC_1) I use to develop the software, I have a simulator which creates a virtual robot that I can test my software with. The software works with the virtual robot without any problem. However, when I move to the PC (PC_2) connected with the actual robot, I can only use the main thread to call DataTable.Refresh()
, and the method called in the BackgroundWorker
would throw the following exception:
System.InvalidCastException: 'Unable to cast COM object of type 'System.__ComObject' to interface type 'FRRJIf._DataTable'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{F7009573-2D48-4A59-BACC-356CAF720DF0}' failed due to the following error: Error loading type library/DLL. (Exception from HRESULT: 0x80029C4A (TYPE_E_CANTLOADLIBRARY)).'
Both PC has the same DLL version, but PC_1 is running Win10 and PC_2 is running Windows 7. According to the exception message, the cause does not appear to be the difference between the virtual and the real robot, but more likely the differences in the software environment of the two PCs. However, I cannot solve it.
If related, the BackgroundWorker_DoWork
method:
private DataTable _dataTable; //initialised from constructor
public BackgroundWorker DataTableBackgroundRefresher;
private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
IsBusy = true;
var bgw = sender as BackgroundWorker;
try
{
while (!bgw.CancellationPending)
{
_dataTable.Refresh();
}
}
catch
{
IsBusy = false;
e.Cancel = true;
throw;
}
IsBusy = false;
e.Cancel = true;
}
The test methods are simply:
DataTable _dataTable; //initialised from Class Initilizer.
[TestMethod]
public async Task RefreshDataTable_mainThread()
{
_dataTable.Refresh();
}
[TestMethod]
public async Task RefreshDataTable_mainThread()
{
DataTableBackgroundRefresher.RunWorkerAsync();
}
User contributions licensed under CC BY-SA 3.0