-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathSqlChangeMonitor.cs
41 lines (36 loc) · 1.36 KB
/
SqlChangeMonitor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// <copyright file="SqlChangeMonitor.cs" company="Microsoft">
// Copyright (c) 2009 Microsoft Corporation. All rights reserved.
// </copyright>
using System;
using System.Data.SqlClient;
using System.Globalization;
namespace System.Runtime.Caching {
public sealed class SqlChangeMonitor : ChangeMonitor {
private String _uniqueId;
private SqlDependency _sqlDependency;
public override String UniqueId { get { return _uniqueId; } }
private SqlChangeMonitor() {} // hide default .ctor
public SqlChangeMonitor(SqlDependency dependency) {
if (dependency == null) {
throw new ArgumentNullException("dependency");
}
bool dispose = true;
try {
_sqlDependency = dependency;
_sqlDependency.OnChange += new OnChangeEventHandler(OnDependencyChanged);
_uniqueId = Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture);
dispose = false;
}
finally {
InitializationComplete();
if (dispose) {
Dispose();
}
}
}
protected override void Dispose(bool disposing) {}
private void OnDependencyChanged(Object sender, SqlNotificationEventArgs e) {
OnChanged(null);
}
}
}