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'

Signature
=======================================================================
Joseph "Beemer Biker" Stateson
http://ResearchRiders.org Ask about my 99'R1100RT
=======================================================================
Bart Mermuys - 29 Jan 2007 19:33 GMT
Hi,
> 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?
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
> 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
[quoted text clipped - 22 lines]
> compiler didnt like the ++: Operator '++' cannot be applied to operand of
> type 'object'