473,387 Members | 1,398 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,387 software developers and data experts.

Cross-Thread Form Binding - Can it be done?

Hello:

I have a business object that reports the updated status of a download
taking place in another thread. I wanted to simplify my code by having
the interface bind to my business object directly. My business object
implements INotifyPropertyChanged.

I get a cross-thread error since the download is taking place in
another thread. What is *the* way for handling this type of issue. If
it makes any difference, I am binding a DataGridView.

Thanks,
Travis
Feb 2 '08 #1
3 3023
Cross-thread form binding? It's not a sound idea. The usual way to
deal with this is to use Invoke and CallBacks. There's a good example
at: http://www.codeproject.com/KB/miscct...essdialog.aspx

Are there few enough lines for the code to be posted here?

Kofi Sarfo
Feb 2 '08 #2
Oops; minor optimisation (that I prep'd for, then forgot...):

replace:
SynchronizationContext.Current.Send(
with:
ctx.Send(

Marc
Feb 2 '08 #3
Because the thread calling the ThreadedBindingList methods may not be the thread that created the list, you will want to move the SyncronizationContext object out of the methods and into a class variable. This way, the sync context will always be the one that created the object:

public class ThreadedBindingList<T: BindingList<T>
{
SynchronizationContext ctx = SynchronizationContext.Current;
protected override void OnAddingNew(AddingNewEventArgs e)
{
//SynchronizationContext ctx = SynchronizationContext.Current;
if (ctx == null)
{ BaseAddingNew(e); }
else
{ ctx.Send(delegate { BaseAddingNew(e); }, null); }
}

void BaseAddingNew(AddingNewEventArgs e)
{ base.OnAddingNew(e); }

protected override void OnListChanged(ListChangedEventArgs e)
{
//SynchronizationContext ctx = SynchronizationContext.Current;
if (ctx == null)
{ BaseListChanged(e); }
else
{ ctx.Send(delegate { BaseListChanged(e); }, null); }
}

void BaseListChanged(ListChangedEventArgs e)
{ base.OnListChanged(e); }
}
Sep 26 '08 #4

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

Similar topics

12
by: * ProteanThread * | last post by:
but depends upon the clique: ...
4
by: David Peach | last post by:
Hello, hope somebody here can help me... I have a query that lists defects recorded in a user defined date range. That query is then used as the source for a Cross Tab query that cross-tabs count...
23
by: Jeff Rodriguez | last post by:
Here's what I want do: Have a main daemon which starts up several threads in a Boss-Queue structure. From those threads, I want them all to sit and watch a queue. Once an entry goes into the...
3
by: aspmonger | last post by:
Hello, I really believe that IE 6 has a new (intentional?) bug that severely limits the capability of dhtml and cross domain scripting. Yesterday, I read an interesting article about the subject and...
6
by: Robert Bravery | last post by:
Hi all, Can some one show me how to achieve a cross product of arrays. So that if I had two arrays (could be any number) with three elements in each (once again could be any number) I would get:...
7
by: Charles | last post by:
I'd like to develop a simple cross-platform application in C++. I'd like it to run in Windows, OS X, PC-BSD and Linux. From my research, it seems I should use Qt or Gtk as a graphical library. Do...
1
by: Otacon22 | last post by:
Hi all, I want to create a robot with a router board based on processor atheros 2.6, called "fonera". I have installed a version of linux, Openwrt and python and i want to use it for some...
6
by: Bart Van der Donck | last post by:
Hello, I'm presenting my new library 'AJAX Cross Domain' - a javascript extension that allows to perform cross-domain AJAX requests. http://www.ajax-cross-domain.com/ Any comments or...
6
by: ampo | last post by:
Hello. Can anyone help with cross-domain problem? I have HTML page from server1 that send xmlHTTPRequest to server2. How can I do it? Thanks.
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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
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,...
0
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,...
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...

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.