thread problems

Dec 10, 2008 at 9:48 AM
Using this line of code:

textboxBoundsX.Text = manager.markers[0].Bounds.Width.ToString();

caused an exception: the markerproperty Bounds runs in a diffrent thread then the GUI-Thread.

I've worked around the problem now, but in the long run it might be better to have an internal fix for that problem.

Maybe you add it to you 'Todo-list'?

Thanks in advance!
Dec 12, 2008 at 3:05 AM
Pollux, I'm glad you reported this, but I'm unable to reproduce this problem; please elaborate.

Class TouchlessMgr has a public member 'Markers' and a private member '_markers', which are you using?
Class Marker doesn't have a member called Bounds. Class MarkerEventData used to before change #26052.
What bounds structure are you referring to?

I've tried dropping the following code into TouchlessDemo's DrawDemo::updateMarker(object sender, MarkerEventArgs args)
Both of these seem to work fine; so I'm not sure how to reproduce your threading problem.

- mike
Dec 12, 2008 at 7:57 AM
Sorry, I just noticed i left out one part of the chain :)


this is the complete line of code, left out the step 'previousdata' or 'currentdata' or whatever one wants to use there.
In fact, as i had to change the code, i dont have the original line of code anymore, sorry.

the problem seems to be that youre somehow getting the camdata (and therefor the markerdata) from an 'outside' ( source (?) and that my way of accessing it leads a problem cause the GUI-element 'textbox' runs on a diffrent thread. I actualy checked the threadIDs during runtime and they where non-identical.

Dont realy know what else I could say, so I try to clearify by pointing out the obvious :)

im calling the 'ToString()'-Methodof the int variable 'width' belonging to the rectangle 'Bounds' belonging to the MarkerEventData 'PreviousData' belonging to the Marker at position zero in the list 'Markers' belonging to the object 'Manager' of type 'TouchlessMgr'.

Hope this helps :)

Dec 12, 2008 at 9:47 PM

This may be a problem with the old code (probably unmanaged WebCamLib), but it seems to be fixed in our latest code.
Try upgrading to the latest version of Touchless, and you should no longer have this problem.
Community member John Conwell volunteered his time to make our new managed C++ WebCamLib, so thank you John!

I successfully ran Console.WriteLine(_tlmgr.Markers[0].Previousdata.X.ToString()); in two places of my DrawDemo.
It works in DrawDemo::updateMarker, which runs on the marker updating event thread, called from the new managed C++ WebCamLib.dll.
It also works in DrawDemo::drawCanvas, which runs on the UI updating thread, called from the client process.

If you are unable to upgrade, it sounds like your event thread solution is a legitimate workaround.
I apologize for the inconvenience that this bug caused you.
I looking to hearing about how your project comes along.

- Mike
Dec 13, 2008 at 4:17 PM
Edited Dec 15, 2008 at 10:16 AM

Hi all,

this a common problem when you try to manipulate GUI elements from another thread.

You can use this simple code snippet to make your code switch to the right thread:

private void SomeEventHandler(object sender, EventArgs e)
    if (this.InvokeRequired)
        Action<object> invoker = new Action<object, EventArgs>(this.SomeEventHandler);
        this.Invoke(invoker, sender, e);
        // your regular code here changing the GUI element, e.g.
        this.SomeTextField.Text = e.ToString();

The example also shows that this could not be done internally in the touchlessLib, as the Invoke(Required) has to be called on the GUI object to be manipulated.

(edit: fixed generic class representation, html editor destroyed the generics)

Dec 15, 2008 at 8:37 AM
Thats exactly what I did :)

Didnt know it was the best way to do it. Thanks eFloh!