all groups > dotnet windows forms databinding > january 2007 >
You're in the

dotnet windows forms databinding

group:

threads: datagridvew works but not textboxes, etc?


threads: datagridvew works but not textboxes, etc? Beemer Biker
1/29/2007 9:58:39 AM
dotnet windows forms databinding:
New to threading in C#, I discovered I needed a delegation mechanism to
update a textbox (for example) from a timer thread. However, the timer
thread seems to have no problem getting data from my datagridview nor
"selecting" a row nor updating an unbound value on that grid. Did I luck
out or will I eventually get a cross thread error?

I have a datagrid of events: start times and duration bound to access mdb.
I used the C# timer (not a waitable timer) as described here
http://www.dotnet247.com/247reference/msgs/43/216845.aspx
to handle my scheduling.

I have a timer to start the event (audio collection) and a second one to
signal it to stop. The one that stops the previous event starts the next
one. The program cycles thru the datagrid and start over running
continuously. It all seems to work, but the first time I put in a
groupbox_ScheduleInfo.text = "Next Production: " +
ScheduledStart.ToLongTimeString() + " " + ScheduledStart.Millisecond;

I got an error that quote "the thread that created groupbox_ was not the
same one that was updating it" (or something to that effect). OK, I
understand I need to delegate the update to the groupbox caption using
ISynchronizeInvoke. But how is it that the same thread can increment an
item in the grid and display it and not get an error?
long iNum =
Convert.ToInt32(dataGridView1.Rows[CurrentFrequency].Cells[ID_SigsAcq].Value)
+ 1;
dataGridView1.Rows[CurrentFrequency].Cells[ID_SigsAcq].Value = iNum;

Also, the above two lines are awkward. I do not know if long is int32 or
int64 and it seems I should be able to do to this all in one line but the
compiler didnt like the ++: Operator '++' cannot be applied to operand of
type 'object'


--
=======================================================================
Joseph "Beemer Biker" Stateson
http://ResearchRiders.org Ask about my 99'R1100RT
=======================================================================

Re: threads: datagridvew works but not textboxes, etc? Bart Mermuys
1/29/2007 7:33:38 PM
Hi,

[quoted text, click to view]

Not sure, but afaik you shouldn't update Controls from another thread then
the one that created them. You could check Form/Control InvokeRequired
property and if it's true then you need to use Invoke or BeginInvoke, even
if it works without.

HTH,
Greetings

[quoted text, click to view]

AddThis Social Bookmark Button