okay so I have an app that updates it's status every second to run tests and grab information from various files/places on a system. My app works great but I get a funny error from time to time: System.InvalidO perationExcepti on "object is being used" (or something similar).
every second a timer sets off an event. this event creates a thread to run the tests as to not freeze the GUI. However before the test is run, it fetches a static boolean that says whether a thread like this is already running or not. if the bool returns true then the thread is not initialized.
here is the code for the timer event:
constants is an abstract class with static methods I use as global values.
now in my run code, once the test has finished, I set
can this be the problem? If yes, how do I get rid of it?
every second a timer sets off an event. this event creates a thread to run the tests as to not freeze the GUI. However before the test is run, it fetches a static boolean that says whether a thread like this is already running or not. if the bool returns true then the thread is not initialized.
here is the code for the timer event:
Code:
private void scheduler_event(object source, System.Timers.ElapsedEventArgs e) { DateTime static_time_now = DateTime.Now; bool pre_busy = constants.busy; constants.busy = true; if (constants.firstrun == true) { constants.firstrun = false; constants.busystatus = new bool[] { false, false, false }; constants.updatestatus = new bool[] { true, true, true }; Thread firstrunthread = new Thread(firstrun); firstrunthread.Start(); } if (pre_busy == false)//when program is fired up, prebusy is set to false { constants.updatestatus[0] = ((constants.next_sysinfo <= static_time_now) && (constants.busystatus[0] == false)); constants.updatestatus[1] = ((constants.next_drive <= static_time_now) && (constants.busystatus[1] == false)); constants.updatestatus[2] = ((constants.next_eventlog <= static_time_now) && (constants.busystatus[2] == false)); Thread runthread = new Thread(run); runthread.Start(); } }
now in my run code, once the test has finished, I set
Code:
constants.busy = false
Comment