Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

C# API Multi Threads problem during get info from RoboDK API

#1
Hi, 
I am using RoboDK C# API to create my project.
I met the problem shown in the attachment picture.

The code is here:
line1:            if (!MainVM.Instance.mRobot.Valid()) return;
line2:            if (!MainVM.Instance.mRoboDK.Connected()) return;
line3:            if (MainVM.Instance.mRobot.Busy()) return;

The 'mRoboDK' is an instance of the interface IRoboDK;
The 'mRobot' is an instance of the interface IItem. In this case it is a robot loaded into the RoboDK.
It's weird that the line1 and line2 work fine. But the line3 has the error:"RoboDk.API.Exceptions.RdkException:“Invalid item provided: The item identifier provided is not valid or it does not exist.”"

In fact there are two threads in my project. I use the 'mRobot' in both threads. If I only leave one of these threads, everything works fine. If I use both, the same error will occur randomly.


Thanks for any advice or suggestion.


Attached Files Thumbnail(s)
   
#2
You should use a new instance of RoboDK/Robolink for each thread. In other words, you can't use the same communication link for multiple threads.

Another option is to lock the usage of the RoboDK API.
#3
That's awesome. I create a new instance of Robolink. It works. Thanks very much!
#4
Great, thank you for your feedback!
  




Users browsing this thread:
1 Guest(s)