Windows Develop Bookmark and Share   
 index > Windows Forms General > DivideByZeroException
 

DivideByZeroException

Hi I am getting a DivideByZeroException on a Invoke statement to update some controls on the GUI. It occurs when I start a timer that is displayed on the GUI (so the GUI label is always updating), and an event fires to update another form control. I guess my question is can this be done?

this is the command that produces the error:

this.Invoke(theDelegateMethod, new object[] { current_runtime_state, coupler_current_state, vehicle_detect_current_state, barcode_scanned,

let_current_state, vehicle_bypass, coupler_bypass, standalone_mode});

any help is appriciated,

thanks

Ross

gdog300  Wednesday, June 27, 2007 4:36 PM
Are you doing any division inside the "theDelegateMethod"? I suspect that Invoke will receive the exception from a division inside the delegate.

Are any of your parameters zero?
IsshouFuuraibou  Wednesday, June 27, 2007 5:35 PM
no there is no division being done, which is the strange part. A couple parameters, however, may be zero
gdog300  Wednesday, June 27, 2007 5:46 PM
Can you post the code for the method you're invoking?

There is a chance that something there might call divide internally.

Another thing you can do, just for testing is to do a try/catch around all the code inside the invoked method, catching DivideByZeroException and see if that catches it, then you know it is from inside the invoked method.
IsshouFuuraibou  Wednesday, June 27, 2007 7:01 PM
i think i came to the conclusionI cant do what I am trying. In order to update my form from another tread I use Invoke which switches the thread to the thread the form was created on. But if the thread the form is created on is constantly in use updating a timer label, I dont think Invoke can switch this other method on this thread to update another form control. Can anyone verify if what I am saying is correct? and is there another way to do this?
gdog300  Friday, June 29, 2007 2:41 PM
If your GUI thread is busy then you can't invoke on it. The Invoke will wait until the GUI thread is free, have the invoked method run, receive the result and continue.

Busy could be with a loop, a too active timer (timespan <5 ms?), any sort of WaitOne/WaitAll/WaitAny.

One question is how short is the timer's elapse time? You do know that changes made < 20 ms are generally not very perceivable by people? Why do you need this timer to basically run constantly, while having the overhead it has to wait, wake up, and queue the event?
IsshouFuuraibou  Friday, June 29, 2007 3:01 PM

You can use google to search for other answers

Custom Search

More Threads

• UI Permission
• Different color for each listbox (or CB) item
• jpeg support of 12 and 16 bit images
• folderBrowserDialog for server-side directories ?
• how to have a drawn line between 2 point(when user click the mouse) using c#
• Startup form not starting focused...
• Converted 2003 - 2008 project no vista styles
• Finding the right Browser window
• TreeViewControl - DoubleClick on a node should not collapse the node
• Databinding Concept