473,602 Members | 2,751 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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",renderE ngine,"Framerat e");
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=renderEngi ne.Framerate.To String()
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 3310
You would have to modify your renderer to take an implementation of
ISynchronizeInv oke. 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 ISynchronizeInv oke.
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 ISynchronizeInv oke, 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",renderE ngine,"Framerat e");
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=renderEngi ne.Framerate.To String()
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
ISynchronizeInv oke. 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(IntPt r windowHandle, ISynchronizeInv oke mainThreadInvok er)
: this(windowHand le)
{
this.mainThread Invoker = mainThreadInvok er;
}

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

In my property I have

delegate void setFramerateCal lback(int framerate);
public int Framerate
{
get
{
return framerate;
}
private set
{
if (mainThreadInvo ker.InvokeRequi red)
{
setFramerateCal lback sfc = new
setFramerateCal lback(setFramer ate);
mainThreadInvok er.Invoke(sfc, new object[] { value });
}
else
framerate = value;
}
}

private void setFramerate(in t rate)
{
Framerate = rate;
}
The databinding in the main form is simply
DataBindings.Ad d("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
mainThradInvoke r.InvokeRequire d 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. OnFramerateUpda ted 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
3857
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 with that stuff... However, as somebody out there probably knows, programmatically setting the DateTimePicker.Value property to a new VALUE does NOT in itself constitute a CHANGE to
2
1715
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 anyone help with the required syntax? if i do TExtbox1.text = x.firstname it works ok, but I want to edit the textbox setting the value of x.firstname.
3
3142
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, depending on which menu item a user selects. Each of these controls follows the same basic pattern: Get a dataset from the database and then display the results using basic databinding. Everything works fine except that I'll occaisionally get an...
10
1148
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. Changing a custom property and calling EndCurrentEdit accepts the new value, stores it in the datasoure and behaves normally. Here is a reproduceable example: First, extend Textbox: Public Class MyTextBox Inherits TextBox
8
2174
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 answered... In 1.1 we always did our own myDataAdapter.fills and we liked that control for lots of good reasons. Now the new DataSource (or is it a TableAdapter:Dataset) automatically fills the Gridview. How can we control that fill? In a...
5
12511
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 update the datasource - awesome, but I have an issue with updating from a different thread. Here is my datasource, a person class that raises the PropertyChanged event: class Person : INotifyPropertyChanged {
9
2303
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 using attributes in the *.aspx page. Everything displays great for the initial load, but whenever I try to add or delete an item (I have controls to do this on the page), it does not seem to be recieving any values for the public variables. Here is...
7
2009
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. I have a textbox's enabled property bound to the IsNew property of an object. this.txtPhone1.DataBindings.Add("Enabled", this.BindingSource, "IsNew", true); So when the IsNew property is true, my textbox is enabled. This is correct
0
4328
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 "Promena". I change content of property "Promena" from "Origin text" to "Changed text" using thread but content of label is still the same - databinding isn´t working according to my vision. Does somebody know, please, why content of label doesn´t change...
0
7993
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8404
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8054
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8268
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6730
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5867
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5440
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
1510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.