473,396 Members | 1,970 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Databinding property of object in other thread

I have an object which runs in a sperate thread, from the main thread, and
while running it updates a public property.
In my main form I defined databinding on the property and I would like to
see this databinding update my form property to reflect the value of the
other components property, but it does not happen.

My binding is Databinding.Add("Text",renderEngine,"Framerate");
When the property is initially set, to minus one, the text property is
updated to reflect this, but later changes do not show.
I tried setting a timer, on the main form, to call my binding with
WriteValue(), but that does nothing to better the situation.
If I, in the timer event, just say Text=renderEngine.Framerate.ToString()
then it works fine, but then I loose the nicity of databinding.

What might be the solution to this problem?

Nov 1 '07 #1
4 3293
You would have to modify your renderer to take an implementation of
ISynchronizeInvoke. Then, you can call the Invoke implementation on that
interface. The Control class implements that interface.

If you don't have the interface implementation, you can set the
property directly. Otherwise, you create the delegate and pass it to the
Invoke method on ISynchronizeInvoke.
Thanks for your answer. If I understand you correctly there is no simple and
clear way of using databinding between threads then?
...but.. passing the form, as an ISynchronizeInvoke, is not that big a deal
after all. The renderer receives things such as handle to render window in
the constructor.
I will try your suggestion and see if it makes sence to connect the
renderers properties that strongly to the form.

Nov 2 '07 #2
Hi Jason,
Why not have the threaded object raise a custom event with the info as
the payload.
regards
Bob
On Thu, 1 Nov 2007 20:35:45 +0100, "Jason Wolf" <a@b.dewrote:
>I have an object which runs in a sperate thread, from the main thread, and
while running it updates a public property.
In my main form I defined databinding on the property and I would like to
see this databinding update my form property to reflect the value of the
other components property, but it does not happen.

My binding is Databinding.Add("Text",renderEngine,"Framerate");
When the property is initially set, to minus one, the text property is
updated to reflect this, but later changes do not show.
I tried setting a timer, on the main form, to call my binding with
WriteValue(), but that does nothing to better the situation.
If I, in the timer event, just say Text=renderEngine.Framerate.ToString()
then it works fine, but then I loose the nicity of databinding.

What might be the solution to this problem?
Nov 3 '07 #3
You would have to modify your renderer to take an implementation of
ISynchronizeInvoke. Then, you can call the Invoke implementation on that
interface. The Control class implements that interface.
I tried your suggestion, as I understand it, and It still doesnt quite do
what I want.

The constructor is now
public GfxEngine(IntPtr windowHandle, ISynchronizeInvoke mainThreadInvoker)
: this(windowHandle)
{
this.mainThreadInvoker = mainThreadInvoker;
}

So I keep the ISynchroniceInvoker for later use. I pass the main form in the
constructor.

In my property I have

delegate void setFramerateCallback(int framerate);
public int Framerate
{
get
{
return framerate;
}
private set
{
if (mainThreadInvoker.InvokeRequired)
{
setFramerateCallback sfc = new
setFramerateCallback(setFramerate);
mainThreadInvoker.Invoke(sfc, new object[] { value });
}
else
framerate = value;
}
}

private void setFramerate(int rate)
{
Framerate = rate;
}
The databinding in the main form is simply
DataBindings.Add("Text", gfxEngine, "Framerate");
And it initializes Text to -1 which is the initial framerate of the
renderer.

When I, from my render thread, call the private set for framerate, the
mainThradInvoker.InvokeRequired is true and the delegate is created (it is
done locally for clarity right now) and it is called and sets the property,
without further invocations.

Any hints as to what I am doing wrong here? Why does it not work?
Secondly, can I not skip the extra setFramerate method and someho use a
property directly as a method in the delegate?

Nov 4 '07 #4
Why not have the threaded object raise a custom event with the info as
the payload.
That was my first verion actually. OnFramerateUpdated which the form
subscribed to. I thought it was nicer to just set up databinding one place
and have it worl automatically under the hood. I still think that is
prettiest, but it seems that it makes the calling end somewhat more messy so
perhaps I will return to the event idea

Nov 4 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Richard | last post by:
Hi, I have a DateTime picker control on a form. The datetime picker control is data bound to a column in a DataTable. Yes I know about bound DateTime pickers and DBNull and etc. so no troubles...
2
by: Colin Robinson | last post by:
Help please I have an example class called Person with 2 public properties Firstname and Lastname, I cant create a textbox on an asp.net form bound to the Person.Firstname property Can...
3
by: Kevin Swanson | last post by:
I'm writing what should be a very simple app against an Oracle database. The app has a number of user controls, any one of which is loaded into a main display page using the loadControl method,...
10
by: Marina | last post by:
Here is the problem. If 2 different properties on the same (or different) control are bound to the same data column, changing the Text property and calling EndCurrentEdit discards the new value. ...
8
by: GaryDean | last post by:
We have been noticing that questions on vs.2005/2.0 don't appear to get much in answers so I'm reposting some questions posted by some of the programmers here in our organization that never got...
5
by: Mark R. Dawson | last post by:
Hi all, I may be missing something with how databinding works but I have bound a datasource to a control and everything is great, the control updates to reflect the state of my datasource when I...
9
by: Nathan Sokalski | last post by:
I have a very simple UserControl which contains an Image and a Label, which I use to display an image with a caption. I am using this control inside a DataList, setting the two Public variables...
7
by: Naveen | last post by:
I posted this message to another board and have hardly had any views on it, leave alone answers. So I am cross-posting here. This may be a very simple question but I can't get my head around it....
0
by: Czechtim | last post by:
Hello, I have problem with databinding. I created small application using structure that I need to demonstrate problem. I need to change content of label when changing content of property...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.