'Declaration Public Class MySqlDependency Implements System.IDisposable
public class MySqlDependency : System.IDisposable
'Declaration Public Class MySqlDependency Implements System.IDisposable
public class MySqlDependency : System.IDisposable
Represents a process that periodically polls the server and fires an event if it detects changes in monitored tables.
MySqlDependency provides several ways to determine if there are changes on the server:
By default, MySqlDependency selects the method to use in the following way: if a table has at least one TIMESTAMP column, the dependency uses it to check for changes; otherwise it uses the CHECKSUM TABLE statement. It also allows you to explicitely specify, which method to use for a command by using the MySqlDependency Constructor(MySqlCommand,Int32,MySqlDependencyCheckType) or AddCommandDependency(MySqlCommand,MySqlDependencyCheckType) overloads with the checkType argument. The latter one determines the method to use for the command: default behavior, or only CHECKSUM TABLE or only timestamp columns. See MySqlDependencyCheckType for more details.
If you want to use your own callback function, use the OnCheck event handler for this.
When specifying the method to use, you need to take the following considerations into account:
The MySqlDependency object uses information from MySqlCommand objects to determine what tables should be checked with the CheckTimeout interval in milliseconds. After you add MySqlCommand objects with the AddCommandDependency(MySqlCommand) method, invoke the Start(String) method with connection string to use when checking for changes. The MySqlDependency object will start polling the server periodically until you invoke the Stop method.
Every time the MySqlDependency object detects that a table has been changed it invokes the OnChange event handler, where you can perform necessary actions.
This class is not available in Mobile Edition.
string connectionString = "User Id=root;Password=root;Host=localhost;Database=test;"; void Start() { MySqlConnection connection = new MySqlConnection(connectionString); connection.Open(); MySqlCommand commandDeptEmp = new MySqlCommand("select * from dept, emp", connection); MySqlCommand commandPict = new MySqlCommand("select * from mysqlnet_pictures", connection); MySqlDependency dependency = new MySqlDependency(commandDeptEmp, 100); dependency.AddCommandDependency(commandPict); dependency.OnChange += new Devart.Data.MySql.OnChangeEventHandler(dependency_OnChange); MySqlDependency.Start(connectionString); } void Stop() { MySqlDependency.Stop(connectionString); } void dependency_OnChange(object sender, Devart.Data.MySql.MySqlTableChangeEventArgs e) { // process changes }
System.Object
Devart.Data.MySql.MySqlDependency
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2