Are SolidEdgeFileProperties API threadsafe ?

Valued Contributor
Valued Contributor

Dear all,    I thank anybody in advance for any kind of help as this problem is really killing me. I'm trying to access (read/write) "Custom" properties of SE files. Usually this is quite easy task and I do it in my program (made in VB.NET) but now I want to embed the function of writing properties to SE file inside a BackgroundWorker...Well actually this seams cannot be done, at least in the same way.I found an exception (that I access protected memory) when I call "Open" method of SolidEdgeFileProperties.PropertySets object.

Any idea?Thanks again

 

Posted by: Giancarlo
Post date: 10/14/2011 3:25:35 AM

7 REPLIES

RE: Are SolidEdgeFileProperties API threadsafe ?

Valued Contributor
Valued Contributor

Hi,

 

unfortunately not. See my answer in the thread with same question/problem:

 

http://www.jasonnewell.net/Community/Forums/tabid/55/aft/4551/Default.aspx

 

Posted by: Wolfgang Kunert
Post date: 10/14/2011 4:35:15 AM

RE: Are SolidEdgeFileProperties API threadsafe ?

Valued Contributor
Valued Contributor

Thanks.Sorry for the double thread. I didn't find that answer.Anyway it's a pity.

 

Posted by: Giancarlo
Post date: 10/14/2011 4:43:42 AM

RE: Are SolidEdgeFileProperties API threadsafe ?

Valued Contributor
Valued Contributor

You can use COM in threads if you know how ;-).  The root of the problem has to do with ApartmentState.  The thread interacting with COM needs to have an ApartmentState of STA.  Unfortunately, the BackgroundWorker class does not expose this functionality.  Fortunately, we can still create threads the old fashion way ourself.  By creating the threads manually, we can set the appropriate apartment state before the thread starts.  The key to making all of this work is Thread.SetApartmentState which I've shown below.

 

using SolidEdgeFileProperties;using System;using System.Text;using System.Threading;using System.Windows.Forms;namespace PropertyThreading{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Thread t = new Thread(new ThreadStart(Go)); t.SetApartmentState(ApartmentState.STA); t.Start(); } static void Go() { /* ApartmentState has to be STA or this will fail. */ if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA) { PropertySets ps = new PropertySetsClass(); ps.Open(@"C:\Part1.par", true); ps.Close(); } } }}

 

Posted by: Jason Newell
Post date: 10/14/2011 7:34:42 AM

RE: Are SolidEdgeFileProperties API threadsafe ?

Valued Contributor
Valued Contributor

Hi Jason,

 

that's exactly what i meant in my answer by saying The BackgroundWorker component doesn't allow to specify the Apartment mode to run in whereas the 'normal' Thread component does.

 

 

Posted by: Wolfgang Kunert
Post date: 10/14/2011 12:43:23 PM

RE: Are SolidEdgeFileProperties API threadsafe ?

Valued Contributor
Valued Contributor

Thanks guys. That solved the problem.

Now I made a class that works similarly to BackgroundWorker (with DoWork and WorkCompleted events) but the thread is STA.

 

Posted by: Giancarlo
Post date: 10/16/2011 9:31:19 PM

Are SolidEdgeFileProperties API threadsafe ?

Valued Contributor
Valued Contributor

Hello all!

 

Giancarlo, i actually have the same problem as you do, i am trying to run my subs which deal with Solid Edge in BackgroundWorker and that just wont work.

Can you please share here your new "BackgroundWorker"?

 

Thank you in advance!

salwadora

 

Posted by: Salwadora
Post date: 1/24/2013 9:28:13 AM

Are SolidEdgeFileProperties API threadsafe ?

Valued Contributor
Valued Contributor

Thank you Jason, I let it run in a new STA thread now and that worked perfectly.

 

Regards, salwadora

 

Posted by: Salwadora
Post date: 1/26/2013 3:30:44 AM