C # real-time monitoring of applets

Source: Internet
Author: User

Real-time Monitoring Applet

Keywords:
Delegate thread asynchronous operation Big Data Stored Procedure paging real-time refresh interface data Sound Alarm taskbar prompt dynamic taskbar icon Switch

Requirements:After the monitoring program is started, it is queried from the background database every 10 seconds (the number of seconds can be configured,
Query conditions (SQL statements can be configured), and then the returned results are displayed and judged.
Condition for determination (flexible configuration as much as possible): How many times the number of null 2 is greater than 0 in the returned data,
It takes another time interval of 1 second. If it is found that it is a multiple of 2, an alarm will be triggered,
If the number of multiples of 0 is greater than 2, it is queried every 10 seconds (configurable ).

Instantly inserted data: (first column)



Program interface:


Configuration:


 
Implementation Code: using System;
Using System. Collections. Generic;
Using System. Configuration;
Using System. Data;
Using System. Drawing;
Using System. IO;
Using System. Runtime. InteropServices;
Using System. Threading;
Using System. Windows. Forms;
Namespace SMMMMonitoring
{
Public partial class Form1: Form
{
Private static string strConn = ConfigurationManager. receivettings ["conStr"];
Private static string strProcedure = ConfigurationManager. AppSettings ["procName"];
Private static int pageindex = Convert. ToInt32 (ConfigurationManager. receivettings ["pageindex"]); // refresh the page
Private static int multiples = Convert. ToInt32 (ConfigurationManager. receivettings ["Multiple"]); // alarm Multiple
StoreProcedure sa = new StoreProcedure (strProcedure, strConn );
Public Form1 ()
{
InitializeComponent ();
BindDGV ();

}
Private void BindDataWithPage (int Index)
{
WinFormPager1.PageIndex = Index;
String table = ConfigurationManager. receivettings ["table"];
String field = ConfigurationManager. receivettings ["Field"];
String orderby = ConfigurationManager. receivettings ["orderby"];
String where = ConfigurationManager. AppSettings ["where"];
DataTable dt = sa. ExecuteDataTable (table, field, orderby, 10, Index, 0, 0, where );
DataGridView1.DataSource = dt;
WinFormPager1.RecordCount = Convert. ToInt32 (sa. ExecuteDataTable (table, field, orderby, 10, Index, 1, 0, where). Rows [0] [0]);
}
Private void winformpagerinclupageindexchanged (object sender, EventArgs e)
{
BindDataWithPage (winFormPager1.PageIndex );
} // The Inter-thread operation is invalid: It is accessed by a thread that does not create the control "dataGridView1.
// Call: BindDGV (9, BindDataWithPage); pass the Parameter
/* Private delegate void BindDGVDelegate (int n );
Private void BindDGV (int n, BindDGVDelegate myDelegate)
{
If (this. InvokeRequired)
{
This. Invoke (myDelegate, n); // synchronous
}
Else
{
MyDelegate (n );
}
}
*/
/*
* The Invoke and BeginInvoke delegate methods of Control are executed on the main thread, that is, the UI thread.
* If your delegate method is used to retrieve long-time data and then update the interface or something,
* Do Not Call Control. Invoke and Control. BeginInvoke on the UI thread. Compared with the invokeThread thread, these operations still block the UI thread and cause the interface to be suspended.
* Use Thread to call BeginInvoke and Invoke
* Execution sequence: A --- BC (B and C are executed simultaneously, B is executed on the thread UI, and C is executed on the beginInvokeThread thread) -- DE
*/
Private Thread beginInvokeThread;
Private delegate void beginInvokeDelegate ();
Private void StartMethod ()
{
// C code segment ...... long-time operations
DataGridView1.BeginInvoke (new beginInvokeDelegate (beginInvokeMethod ));
// D code segment ...... Delete
}
Private void beginInvokeMethod ()
{
// Method for updating the interface of the ecode segment.
BindDataWithPage (pageindex );
}
Private void BindDGV ()
{
// A code snippet .......
BeginInvokeThread = new Thread (new ThreadStart (StartMethod ));
BeginInvokeThread. Start ();
// B code segment ......
} // <Summary>
/// An alarm is triggered when it is more than several times
/// </Summary>
/// <Param name = "dgv"> </param>
/// <Param name = "n"> </param>
Public bool Alarm (DataGridView dgv, int n)
{
Int Space = 0; int Success = 0;
Dictionary <string, int> dict = DictionaryColumns (dgv );
Foreach (KeyValuePair <string, int> kvp in dict)
{
If (kvp. Key = "2 ")
{
Space = kvp. Value;
}
If (kvp. Key = "0 ")
{
Success = kvp. Value;
}
}
If (Space> = Success * n)
{
// Alarm
// MessageBox. Show ("alarm! "," Message prompt ", MessageBoxButtons. OK, MessageBoxIcon. Information );
Return true;
}
Else
{
// MessageBox. Show ("bu alarm! "," Message prompt ", MessageBoxButtons. OK, MessageBoxIcon. Information );
Return false;
& Nbs

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.