Click here to Skip to main content
15,899,679 members
Home / Discussions / C#
   

C#

 
AnswerRe: Question about using Zedgraph Pin
Not Active12-Dec-10 5:17
mentorNot Active12-Dec-10 5:17 
GeneralRe: Question about using Zedgraph Pin
Rafone12-Dec-10 6:32
Rafone12-Dec-10 6:32 
GeneralRe: Question about using Zedgraph Pin
Thomas Krojer30-Dec-10 3:44
Thomas Krojer30-Dec-10 3:44 
GeneralRe: Question about using Zedgraph Pin
Rafone30-Dec-10 5:16
Rafone30-Dec-10 5:16 
AnswerRe: Question about using Zedgraph Pin
Thomas Krojer12-Dec-10 23:42
Thomas Krojer12-Dec-10 23:42 
GeneralRe: Question about using Zedgraph Pin
Rafone13-Dec-10 3:45
Rafone13-Dec-10 3:45 
GeneralRe: Question about using Zedgraph Pin
Thomas Krojer13-Dec-10 3:59
Thomas Krojer13-Dec-10 3:59 
Questionwhy not responding? Pin
Jassim Rahma12-Dec-10 2:48
Jassim Rahma12-Dec-10 2:48 
I have a simple application with a timer (interval 5min) to read the simple data from mysql server.. The application is just one form but it's freezing after the code runs! why is that?

here is the full code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using MySql.Data;
using MySql.Data.MySqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Configuration;
using System.Threading;

namespace Cure_Server
{
    public partial class frmMain : DevExpress.XtraEditors.XtraForm
    {
        MySqlConnection sql_connection = null;
        MySqlCommand sql_command = null;
        MySqlDataAdapter sql_adapter;
        DataTable data_table = null;
        MySqlDataReader sql_reader = null;
        DataSet data_set = null;

        public public_class public_var = new public_class();

        const int MF_BYPOSITION = 0x400;

        [DllImport("User32.dll")]
        private static extern int RemoveMenu(IntPtr hMenu, int nPosition, int wFlagS);

        [DllImport("User32.dll")]
        private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);

        [DllImport("User32.dll")]
        private static extern int GetMenuItemCount(IntPtr hWnd);

        public int result_rows;

        public frmMain()
        {
            InitializeComponent();
        }

        private void perform()
        {
            get_statistics_summary();
            send_sms();
        }

        private void get_statistics_summary()
        {
            progressRunning.Visible = true;

            try
            {
                // sql_connection = new SqlConnection("Data Source=.\\SQLEXPRESS;initial catalog=shefa;integrated security=true");
                sql_connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["SQLdb"].ConnectionString);
                sql_connection.Open();
                sql_command = new MySqlCommand("SELECT COUNT(*) AS total_files FROM persons", sql_connection);
                sql_command.CommandType = CommandType.Text;
                sql_reader = sql_command.ExecuteReader();

                if (sql_reader.Read())
                {
                    lblTotalFiles.Text = sql_reader["total_files"].ToString();
                }

                sql_reader.Close();

                sql_command = new MySqlCommand("SELECT COUNT(*) AS total_appointments FROM appointments", sql_connection);
                sql_command.CommandType = CommandType.Text;
                sql_reader = sql_command.ExecuteReader();

                if (sql_reader.Read())
                {
                    lblTotalAppointments.Text = sql_reader["total_appointments"].ToString();
                }
            }
            catch (Exception exp)
            {
                return;
            }
            finally
            {
                if (sql_reader != null) sql_reader.Close();
                if (sql_connection != null)
                {
                    if (sql_connection.State == ConnectionState.Open)
                        sql_connection.Close();
                }
            }

            progressRunning.Visible = false;
        }

        private void send_sms()
        {
            progressRunning.Visible = true;

            try
            {
                sql_connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["SQLdb"].ConnectionString);
                sql_connection.Open();
                sql_command = new MySqlCommand("sp_send_pending_sms", sql_connection);
                sql_command.CommandType = CommandType.StoredProcedure;
                sql_reader = sql_command.ExecuteReader();

                while (sql_reader.Read())
                {
                    lblTimer.Text = sql_reader["sms_queue_id"].ToString();
                }
            }
            catch (Exception exp)
            {
                return;
            }
            finally
            {
                if (sql_reader != null) sql_reader.Close();
                if (sql_connection != null)
                {
                    if (sql_connection.State == ConnectionState.Open)
                        sql_connection.Close();
                }
            }

            progressRunning.Visible = false;
        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;

            IntPtr hMenu = GetSystemMenu(this.Handle, false);
            int menuItemCount = GetMenuItemCount(hMenu);
            RemoveMenu(hMenu, menuItemCount - 1, MF_BYPOSITION);

            timerMain.Interval = Convert.ToInt32(ConfigurationManager.AppSettings["ServerTimerInterval"]);

            // public_var.get_system_properties();
        }

        private void btnEmailTemplates_Click(object sender, EventArgs e)
        {
            frmEmailTemplates EmailTemplatesForm = new frmEmailTemplates(public_var);
            EmailTemplatesForm.ShowDialog();
        }

        private void frmMain_Shown(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;

            timerMain.Start();

            this.Cursor = Cursors.Default;
        }

        private void btnConnectonFile_Click(object sender, EventArgs e)
        {

        }

        private void timerMain_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            // lblTimer.Text = DateTime.Now.ToString();
            backgroundWorkerSMS.RunWorkerAsync();

            // send_sms();
        }

        private void btnOptions_Click(object sender, EventArgs e)
        {
            timerMain.Stop();

            frmOptions OptionsForm = new frmOptions();
            DialogResult options_form = OptionsForm.ShowDialog();

            if (options_form == DialogResult.OK)
            {
                timerMain.Interval = Convert.ToInt32(ConfigurationManager.AppSettings["ServerTimerInterval"]);
            }

            timerMain.Start();
        }

        private void backgroundWorkerSMS_DoWork(object sender, DoWorkEventArgs e)
        {
            timerMain.Stop();

            perform();
        }

        private void backgroundWorkerSMS_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            backgroundWorkerSMS.Dispose();
            timerMain.Start();
        }
    }
}

AnswerRe: why not responding? Pin
Luc Pattyn12-Dec-10 3:04
sitebuilderLuc Pattyn12-Dec-10 3:04 
AnswerRe: why not responding? PinPopular
Not Active12-Dec-10 3:43
mentorNot Active12-Dec-10 3:43 
GeneralRe: why not responding? Pin
Luc Pattyn12-Dec-10 5:46
sitebuilderLuc Pattyn12-Dec-10 5:46 
GeneralRe: why not responding? Pin
Jassim Rahma13-Dec-10 2:49
Jassim Rahma13-Dec-10 2:49 
GeneralRe: why not responding? Pin
Not Active13-Dec-10 3:28
mentorNot Active13-Dec-10 3:28 
QuestionHow can I filter certain messages in log4net Pin
Berlus11-Dec-10 23:54
Berlus11-Dec-10 23:54 
AnswerRe: How can I filter certain messages in log4net Pin
fjdiewornncalwe12-Dec-10 3:50
professionalfjdiewornncalwe12-Dec-10 3:50 
AnswerRe: How can I filter certain messages in log4net Pin
Manfred Rudolf Bihy12-Dec-10 4:39
professionalManfred Rudolf Bihy12-Dec-10 4:39 
GeneralRe: How can I filter certain messages in log4net Pin
Berlus12-Dec-10 11:04
Berlus12-Dec-10 11:04 
AnswerRe: How can I filter certain messages in log4net Pin
Pete O'Hanlon13-Dec-10 0:34
mvePete O'Hanlon13-Dec-10 0:34 
Questiongadgets in windows form Pin
Zeyad Jalil11-Dec-10 23:06
professionalZeyad Jalil11-Dec-10 23:06 
AnswerRe: gadgets in windows form Pin
Eddy Vluggen12-Dec-10 0:47
professionalEddy Vluggen12-Dec-10 0:47 
Questionsetting label.Text by the SqlDataReader's value Pin
Erdinc2711-Dec-10 2:34
Erdinc2711-Dec-10 2:34 
AnswerRe: setting label.Text by the SqlDataReader's value Pin
Henry Minute11-Dec-10 3:46
Henry Minute11-Dec-10 3:46 
AnswerRe: setting label.Text by the SqlDataReader's value [modified] Pin
PIEBALDconsult11-Dec-10 4:41
mvePIEBALDconsult11-Dec-10 4:41 
GeneralRe: setting label.Text by the SqlDataReader's value Pin
Erdinc2711-Dec-10 5:07
Erdinc2711-Dec-10 5:07 
GeneralRe: setting label.Text by the SqlDataReader's value Pin
PIEBALDconsult11-Dec-10 6:52
mvePIEBALDconsult11-Dec-10 6:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.