1: static void bwRoomStatus_DoWork(object sender, DoWorkEventArgs e)
2: {
3: AdsConnection cn;
4: AdsCommand cmd;
5: AdsDataReader dr;
6:
7: cn = new AdsConnection(sConnection);
8: cmd = cn.CreateCommand();
9:
10: try
11: {
12: // Connect using the same path as the application
13: cn.Open();
14:
15: // Create the RoomStatus event for this connection
16: cmd.CommandText = "EXECUTE PROCEDURE sp_CreateEvent('RoomStatus', 0)";
17: cmd.ExecuteNonQuery();
18: }
19: catch (AdsException aex)
20: {
21: if (aex.Number == 5051)
22: {
23: // Event already exists so continue
24: }
25: else
26: {
27: e.Result = aex;
28: return;
29: }
30: }
31:
32: while (!e.Cancel)
33: {
34: // Wait for the RoomStatus event for up to 5 seconds
35: cmd.CommandText = "EXECUTE PROCEDURE sp_WaitForEvent('RoomStatus', 5000, 0, 0)";
36:
37: dr = cmd.ExecuteReader();
38:
39: // check to see if the room status was updated
40: dr.Read();
41: if (dr.GetInt32(1) > 0)
42: {
43: bwRoomStatus.ReportProgress(100);
44: }
45: dr.Close();
46:
47: // Check to see if the worker has been canceled
48: if (bwRoomStatus.CancellationPending)
49: e.Cancel = true;
50: }
51:
52: // Close the connection
53: cn.Close();
54: }