c# threading with COM

SEVI

Well-known member
Joined
Jun 28, 2003
Messages
48
Location
Australia
HELP!!

I am working with a LEADTOOL Raster COM imaging component which is basically an enhanced picturebox that I am using to implement various transition effects when swapping one image to another. I am trying to implement threading so I can have multiple transitions occur simultaneously. The COM component is supposed to be thread-safe.

There is a property on the control EnableProgressEvents that if set to true will call a method ie Progress() 100 times, similar to a callback I guess, throughout progress of the transition effect. This is intended to be used as a means of cancelling the process, I am trying to use the method as an opportunity to pause the thread so that the other threads can catch up, creating the appearance that all transitions are occurring at once.

The transition effect is triggered by the use of the components Load method. So I wrote some c# code that will spawn two threads from the main thread, each thread will call Object.Load(). In Object.Progress() I tried Thread.Sleep(100) & Thread.Suspend() in an attempt to interrupt the thread 1 and hand over execuion to the thread 2. Upon running the code, the transition did occur but sequentially, not simultaneously. Using some verbose output to see what was happening, I could see the new threads, each calling Object.Load(), however the activity in the Object.Progress() was actioned by the main thread not the spawned threads.

Is there something that I am missing here? Any ideas would be much appreciated.
 
I sorted this out in the end.. quite logical now that I think about it.

COM objects should only be aware of a single thread. When the object was created it was using the main thread, then the spawned thread called the Object.Load() method.

It did work by first spawing the two threads, each thread created its own object and the Object.Load() method was called from the same thread that created the object.

I also had to comment out the OCXState property. Still havent figured out what this property does exactly!! Any ideas?
 
Back
Top