public void GetQuestions(Object stateinfo) { TestRemote tr = (TestRemote)stateinfo; var questions = RemoteQuestionDAL.GetQuestions(tr.TestId); if (questions != null) { this.Invoke((MethodInvoker) delegate { listBox1.DataSource = questions.ToList <Question>(); // runs on UI thread button1.Enabled = true; button1.Text = OldText; }); } else { MessageBox.Show("No questions returned"); this.Invoke((MethodInvoker) delegate { button1.Enabled = true; button1.Text = OldText; }); } }
public TestHelper(Test test) { TestObj = test; questions = new List <Question>(RemoteQuestionDAL.GetQuestions(test.Id)); test.CurrentQuestion = 0; test.SecondsElapsed = 0; timer = new Timer(); timer.Interval = 1000; // one second interval timer.Enabled = true; timer.Elapsed += new ElapsedEventHandler(OnTimedEvent); test.Running = false; }
private void OnTimer(object source, EventArgs e) { if (!test.TestObj.Running) { timer.Stop(); test.stop(); int testresultid = -1; int questions = RemoteQuestionDAL.GetQuestions(test.TestObj.Id).Length; testresultid = RemoteTestResultDAL.AddTestResult(test.TestObj.UserId, test.TestObj.Id, DateTime.Now, test.TestObj.SecondsElapsed, test.TestObj.Correct, questions, test.TestObj.Name); //TestResultDAL.AddTestResult(test.TestObj); MessageBox.Show(RemoteTestResultDAL.GetTestResult(testresultid).ToString()); instance.Dispose(); this.Refresh(); } this.Refresh(); }