• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 644
  • Last Modified:

Need help with Windows form timer not going out to SQL Server database and refreshing records shown in C#?

This question is a continuance from this previous question:  http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_26984217.html

Although the answer has prevented the error message I was getting, the problem now is that the timer never runs the refresh code because (Form.ActiveForm == null) is always true.

Please let me provide some context on what I'm trying to accomplish.  I basically have a pop-up form (frmMain) that is loaded upon startup that checks a sql server database for some records - if some rows then show the records in a datagrid (dgvLogger).  The form has a timer (tRecords) upon every minute to check the sql server database for more rows (People_Logged_In) and if you do have a difference show the new updated VisualData() in the datagrid.  

It never fires because the ActiveForm Is always null but regardless if its not the active form I do need it to check sql server and update the datagrid.


But I was wondering if I need to change this solution to have two forms - one non-visible form to load the second form that has the datagrid.  And if there are records make the second form visible with the updated info and if no records make the second form invisible?  

Or can I make it work with the one Windows application form?
public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();

        }

        private void frmMain_Load(object sender, EventArgs e)
        {

            VisualData();
        }

        public void VisualData()

        {
            ArrayList sequence = new ArrayList();

            string sSQL = "";

            // had to adjust CHARINDEX('\\' 

            sSQL = "SELECT REPLACE(REVERSE(LEFT(REVERSE(DBName),CHARINDEX('\\', REVERSE(DBName),1)-1)), '.accdb', '') AS [Database Name], Access_USERS.[Full Name] as [User], Access_USERS.EXt as Ext, Access_USERS.CPU, substring(convert(varchar(20), Access_LOGGER.InDate, 9), 13, 5) as [Time In]";
            sSQL = sSQL + " FROM (Access_LOGGER INNER JOIN Access_DBLIST ON Access_LOGGER.fDBID = Access_DBLIST.ID) INNER JOIN Access_USERS ON Access_LOGGER.fUserID = Access_USERS.ID";
            sSQL = sSQL + " WHERE Access_USERS.WinSign<>'slecompte' AND Access_LOGGER.OutDate Is Null";
            sSQL = sSQL + " ORDER BY [Time In]";


            SqlConnection sqlCon = null;
            //test server

            string conn = "Data Source=EC-SQL;Initial Catalog=NEWEQ;User Id=NEWEQ;Password=n3w3@!;Connect Timeout=5";

            sqlCon = new SqlConnection();
            sqlCon.ConnectionString = conn;

            try
            {
                sqlCon.Open();         
            }
            catch
            {
                sqlCon.Close();
                sqlCon.Dispose();
                System.Environment.Exit(0);
                return;
            }

            sqlCon.Close();
            sqlCon.Dispose();
            // do not put \\EC-SQL front of

            conn = "Data Source=EC-SQL;Initial Catalog=NEWEQ;User Id=NEWEQ;Password=n3w3@!;";

            



            try
            {
                sqlCon = new SqlConnection();
                sqlCon.ConnectionString = conn;
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = sqlCon;
                cmd.CommandText = sSQL;

            
                sqlCon.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    LogInfo m = new LogInfo();
                    m.DBName = reader[0].ToString();
                    m.User = reader[1].ToString();
                    m.Ext = reader[2].ToString();
                    m.CPU = reader[3].ToString();
                    m.TimeIn = reader[4].ToString();

                    //MessageBox.Show(reader[0].ToString());

                    sequence.Add(m);
                }

                dgvLogger.DataSource = sequence;

            }



            finally
            {
                sqlCon.Close();
            }


        }

        private void frmMain_MouseClick(object sender, MouseEventArgs e)
        {
            Form.ActiveForm.Opacity = 100;
        }

        private void frmMain_Leave(object sender, EventArgs e)
        {
            Form.ActiveForm.Opacity = 90;
        }

        private void tRecords_Tick(object sender, EventArgs e)
        {
            if (People_Logged_In() == true)
            {
                if (Form.ActiveForm == null)
                {
                }
                else
                {
                    dgvLogger.Rows.Clear();
                    VisualData();
                    Form.ActiveForm.Visible = true;
                }
            }
            else
            {
                if (Form.ActiveForm == null)
                {
                }
                else
                {
                    Form.ActiveForm.Visible = false;
                }
            }

        }

        //
        
        private static Boolean People_Logged_In()
        {

            if (Form.ActiveForm == null)
            {
                return false;

            }
            frmMain.ActiveForm.Text = "EC Access databases users:   **** checking status ****";

            System.Windows.Forms.Application.DoEvents();

            Boolean bHasRows;
            string sSQL = "";

            // had to adjust CHARINDEX('\\' 

            sSQL = "SELECT REPLACE(REVERSE(LEFT(REVERSE(DBName),CHARINDEX('\\', REVERSE(DBName),1)-1)), '.accdb', '') AS [Database Name], Access_USERS.[Full Name] as [User], Access_USERS.EXt as Ext, Access_USERS.CPU, substring(convert(varchar(20), Access_LOGGER.InDate, 9), 13, 5) as [Time In]";
            sSQL = sSQL + " FROM (Access_LOGGER INNER JOIN Access_DBLIST ON Access_LOGGER.fDBID = Access_DBLIST.ID) INNER JOIN Access_USERS ON Access_LOGGER.fUserID = Access_USERS.ID";
            sSQL = sSQL + " WHERE Access_USERS.WinSign<>'slecompte' AND Access_LOGGER.OutDate Is Null";
            sSQL = sSQL + " ORDER BY [Time In]";

            // do not put \\EC-SQL front of

            string conn = "Data Source=EC-SQL;Initial Catalog=NEWEQ;User Id=NEWEQ;Password=n3w3@!;";

            SqlConnection sqlCon = null;
            //try
            //{
                sqlCon = new SqlConnection();
                sqlCon.ConnectionString = conn;
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = sqlCon;
                cmd.CommandText = sSQL;
                sqlCon.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                bHasRows = reader.HasRows;

                frmMain.ActiveForm.Text = "EC Access databases users:";
                System.Windows.Forms.Application.DoEvents();

                if (bHasRows == true)
                {
                    return true;
                } 
                else 
                {
                    return false;
                }
            //}

            //finally
            //{

                sqlCon.Close();

            //}

            //frmMain.ActiveForm.Text = "EC Access databases users:";
            //System.Windows.Forms.Application.DoEvents();

        }

    }

Open in new window

0
stephenlecomptejr
Asked:
stephenlecomptejr
  • 24
  • 15
1 Solution
 
UnifiedISCommented:
Can you explain why you are checking the whether or not activeform-== null?
It seems like you just need to query the db every minute and show the form if the counts differ from minute to minute.
0
 
stephenlecomptejrAuthor Commented:
UnifiedIS,
Based on the previous question shown above in a URL - I was getting an error -- NullReferenceException was unhandled - error when using startup form in C Sharp?
0
 
stephenlecomptejrAuthor Commented:
"It seems like you just need to query the db every minute and show the form if the counts differ from minute to minute." - This is the correct.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
databoksCommented:
I recommend do thing  this in a Thread.


Create a new Thread. Set the Thread.Sleep() method to 60000(1 min). then Fire you query at the db.


If you need any help with this please let me know.
0
 
stephenlecomptejrAuthor Commented:
databoks,

I definitely need help with this.  Sorry didn't respond earlier must have missed your post.

Based on the following...

http://www.codeproject.com/KB/cs/ThreadsinC_.aspx
http://www.csharp-examples.net/create-new-thread/

... I tried:

Thread MyThread = new Thread(new ThreadStart (MyCallbackFunction));
            MyThread.Start();
but when I do

MyThread.S     <-------------Sleep doesn't come up as one of the options.

I also have a second problem....

in that I need to change the following frmMain_Load function to...

public static void MyCallbackFunction()

        {

            if (People_Logged_In() == true)
            {
                if (Form.ActiveForm == null)
                {
                }
                else
                {
                    dgvLogger.Rows.Clear();
                    VisualData();
                    Form.ActiveForm.Visible = true;
                }
            }
            else
            {
                if (Form.ActiveForm == null)
                {
                }
                else
                {
                    Form.ActiveForm.Visible = false;
                }
            }

        }

But the problem i that I get an error -

Error      3      An object reference is required for the non-static field, method, or property 'Logger.frmMain.dgvLogger'      C:\Users\slecompte\documents\visual studio 2010\Projects\Logger\Logger\frmMain.cs      137      21      Logger
Error      4      An object reference is required for the non-static field, method, or property 'Logger.frmMain.VisualData()'      C:\Users\slecompte\documents\visual studio 2010\Projects\Logger\Logger\frmMain.cs      138      21      Logger

private void frmMain_Load(object sender, EventArgs e)
        {

            VisualData();
            Thread MyThread = new Thread(new ThreadStart (MyCallbackFunction));
            MyThread.Start();

        }

Open in new window

0
 
stephenlecomptejrAuthor Commented:
I can see there is a sleep for thread...but please note image that I have.

Thanks.


ee-no-sleep.png
0
 
stephenlecomptejrAuthor Commented:
I meant to say I can see where you got Sleep from according to the following URL:
http://www.mycsharpcorner.com/Post.aspx?postID=42
0
 
databoksCommented:
Hi Mate.

Sorry for my late response.

Here is a code Example. You can modify it to your need. However i first create a form. Call it "ThreadSample".
Add a TextBox and a Button to the form and Copy paste the whole code.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace ThreadSample
{
    public partial class Form1 : Form
    {
        Thread SQLDataCheckerThread;
        
            
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.FormClosed += new FormClosedEventHandler(Form1_FormClosed);
            SQLDataCheckerThread = new Thread(new ThreadStart(CheckForNewData));
            SQLDataCheckerThread.Start();
            
            

        }

        void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {

            //Closes the Thread after you closed your form.. This is important..
            SQLDataCheckerThread.Abort();
            
        }

        void CheckForNewData()
        {
            while (true)
            {

                Thread.Sleep(60000);

                textBox1.BeginInvoke((MethodInvoker)delegate()
                {



                    textBox1.Text += "One Minute has now elapsed.. Checking for new data..." + DateTime.Now.ToLongTimeString() + Environment.NewLine;
                });

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show("JAcks");
        }
    }
}

Open in new window



Every program is started in a single thread(this is the Main method). If you call the Thread.Sleep() method - which is static you whole program stops responding until the TimeSpan value in The Sleep() method has elapsed.

However when you have another Thread you program are now running mulitple threads and then your program are responseable to the user(this is good, and this required).

So the Button is just a illustration for you to click and it shows a messagebox so you can see that it checks for data in the SQL Database in background while your users can still do other things in the Program.

Lets take one problem at a time. Try this, see if this is what you need exactly, if not get back to me and i will be more than happy to help you out.



0
 
databoksCommented:
Sorry my english is not the best thing.


The Button is just showing a MessageBox. The SQLDataChecker is running in the Background to check for data in the SQL Database - You can click so many times you want and then your program will still check for data values.


See the attached picture for more results.
ThreadExample.png
0
 
databoksCommented:
As you can see it is exactly precise. One minute all the time. So you can trust on the Threads.


0
 
stephenlecomptejrAuthor Commented:
databoks, I've got the thread working thanks to your great example and I appreciate it.

But its now giving me the same NullReferenceException was unhandled... at Form.ActiveForm.Visible = true....which goes back to the original question...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Collections;
using System.Threading;

namespace Logger
{
    public partial class frmMain : Form
    {

        Thread SQLDataCheckerThread;


        public frmMain()
        {
            InitializeComponent();

        }

        private void frmMain_Load(object sender, EventArgs e)
        {
            VisualData();

            this.FormClosed += new FormClosedEventHandler(frmMain_FormClosed);
            SQLDataCheckerThread = new Thread(new ThreadStart(CheckForNewData));
            SQLDataCheckerThread.Start();

        }

        void CheckForNewData()
        {
            while (true)
            {

                Thread.Sleep(60000);

                if (People_Logged_In() == true)
                {
                    
                    {

                       
                        Form.ActiveForm.Visible = true;
                    }
                }
                else
                {
                    
                //        Form.ActiveForm.Visible = false;
                
                }

            }
        }

Open in new window

errorwithnull.png
0
 
stephenlecomptejrAuthor Commented:
All I'm trying to do here if People_Logged_In is true (which means that there are records to be shown in the frmMain) then show the form - if there is no records to be shown make the frmMain invisible....  Then when another minute passes - if there are records - then make frmMain visible with the new records...
0
 
stephenlecomptejrAuthor Commented:
Once I solve this issue, I have one other that I"ve posted here... (that's a continuance of this situation)
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_27036751.html
0
 
databoksCommented:
Make your life much easier - use the Hide() method.


So your code should like this:

if(People_Logged_In == true)
{

   Form.Show();

}
else

{
   Form.Hide();

}


Try this and let me help with the other problems.
0
 
databoksCommented:
As i said earlier let us examine one problem at a time.

I will look at you other problem.
0
 
stephenlecomptejrAuthor Commented:
databoks, when I try the above, please note the image error I get below:
ee-form-show.png
0
 
stephenlecomptejrAuthor Commented:
when I try the suggestion below I get this also...
ee-form-show2.png
0
 
databoksCommented:
You have two forms right?

One is the main form and the other is the dgvlogger Form.


You have to make an instance of that Form.

Make it here:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Collections;
using System.Threading;

namespace Logger
{
    public partial class frmMain : Form
    {

        Thread SQLDataCheckerThread;
      DgvLoggerForm frmSQL = new DgvLogger(); // The form you want to show and hide();

        public frmMain()
 }







When you want to show the form you do this:

frmSQL.Show(); and frmSQL.Hide();


This is the simplest way.
This should be it.


0
 
databoksCommented:
I have look at your project and udated it.


Look at the other question and get the files.
0
 
databoksCommented:
Forget my earlier post - just get the project from the link and you are ready to go.
0
 
stephenlecomptejrAuthor Commented:
databoks,

Got to really test it today live and its still giving an error -

error-showing-the-form.png
0
 
stephenlecomptejrAuthor Commented:
0
 
databoksCommented:
Please ADD your solution again. I Will look at it. If possible the dB A's well
0
 
stephenlecomptejrAuthor Commented:
0
 
databoksCommented:
Try this:
 public void VisualData()

        {
            //ArrayList sequence = new ArrayList();

            string sSQL = "";

            // had to adjust CHARINDEX('\\' 

            sSQL = "SELECT REPLACE(REVERSE(LEFT(REVERSE(DBName),CHARINDEX('\\', REVERSE(DBName),1)-1)), '.accdb', '') AS [Database Name], Access_USERS.[Full Name] as [User], Access_USERS.EXt as Ext, Access_USERS.CPU, substring(convert(varchar(20), Access_LOGGER.InDate, 9), 13, 5) as [Time In]";
            sSQL = sSQL + " FROM (Access_LOGGER INNER JOIN Access_DBLIST ON Access_LOGGER.fDBID = Access_DBLIST.ID) INNER JOIN Access_USERS ON Access_LOGGER.fUserID = Access_USERS.ID";
            sSQL = sSQL + " WHERE Access_LOGGER.OutDate Is Null";
            sSQL = sSQL + " ORDER BY [Time In]";


            SqlConnection sqlCon = null;
            //test server

            string conn = "Data Source=EC-SQL;Initial Catalog=NEWEQ;User Id=NEWEQ;Password=n3w3@!;Connect Timeout=5";

            sqlCon = new SqlConnection();
            sqlCon.ConnectionString = conn;

            try
            {
                sqlCon.Open();         
            }
            catch
            {
                sqlCon.Close();
                sqlCon.Dispose();
                System.Environment.Exit(0);
                return;
            }

            sqlCon.Close();
            sqlCon.Dispose();
            // do not put \\EC-SQL front of

            conn = "Data Source=EC-SQL;Initial Catalog=NEWEQ;User Id=NEWEQ;Password=n3w3@!;";

            try
            {
                sqlCon = new SqlConnection();
                sqlCon.ConnectionString = conn;
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = sqlCon;
                cmd.CommandText = sSQL;

            
                sqlCon.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    LogInfo m = new LogInfo();
                    m.DBName = reader[0].ToString();
                    m.User = reader[1].ToString();
                    m.Ext = reader[2].ToString();
                    m.CPU = reader[3].ToString();
                    m.TimeIn = reader[4].ToString();

                    //MessageBox.Show(reader[0].ToString());

                    //sequence.Add(m);
                }

                //This removes the Cross-Thread Exception.. You also have to Invoke the Object/Control it is created within another Thread.
                dgvLogger.BeginInvoke((MethodInvoker)delegate()
                {
                    dgvLogger.DataSource = reader;
                });
            }

            finally
            {
                sqlCon.Close();
            }


        }

Open in new window


if this doesnt work then try this:
 public void VisualData()

        {
            //ArrayList sequence = new ArrayList();

            string sSQL = "";

            // had to adjust CHARINDEX('\\' 

            sSQL = "SELECT REPLACE(REVERSE(LEFT(REVERSE(DBName),CHARINDEX('\\', REVERSE(DBName),1)-1)), '.accdb', '') AS [Database Name], Access_USERS.[Full Name] as [User], Access_USERS.EXt as Ext, Access_USERS.CPU, substring(convert(varchar(20), Access_LOGGER.InDate, 9), 13, 5) as [Time In]";
            sSQL = sSQL + " FROM (Access_LOGGER INNER JOIN Access_DBLIST ON Access_LOGGER.fDBID = Access_DBLIST.ID) INNER JOIN Access_USERS ON Access_LOGGER.fUserID = Access_USERS.ID";
            sSQL = sSQL + " WHERE Access_LOGGER.OutDate Is Null";
            sSQL = sSQL + " ORDER BY [Time In]";


            SqlConnection sqlCon = null;
            //test server

            string conn = "Data Source=EC-SQL;Initial Catalog=NEWEQ;User Id=NEWEQ;Password=n3w3@!;Connect Timeout=5";

            sqlCon = new SqlConnection();
            sqlCon.ConnectionString = conn;

            try
            {
                sqlCon.Open();         
            }
            catch
            {
                sqlCon.Close();
                sqlCon.Dispose();
                System.Environment.Exit(0);
                return;
            }

            sqlCon.Close();
            sqlCon.Dispose();
            // do not put \\EC-SQL front of

            conn = "Data Source=EC-SQL;Initial Catalog=NEWEQ;User Id=NEWEQ;Password=n3w3@!;";

            try
            {
                sqlCon = new SqlConnection();
                sqlCon.ConnectionString = conn;
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = sqlCon;
                cmd.CommandText = sSQL;

            
                sqlCon.Open();
                SqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    LogInfo m = new LogInfo();
                    m.DBName = reader[0].ToString();
                    m.User = reader[1].ToString();
                    m.Ext = reader[2].ToString();
                    m.CPU = reader[3].ToString();
                    m.TimeIn = reader[4].ToString();

                    //MessageBox.Show(reader[0].ToString());

                    //sequence.Add(m);
                }

                //This removes the Cross-Thread Exception.. You also have to Invoke the Object/Control it is created within another Thread.
                dgvLogger.BeginInvoke((MethodInvoker)delegate()
                {
                    dgvLogger.DataSource = reader.AsQueryable();
                });
            }

            finally
            {
                sqlCon.Close();
            }


        }

Open in new window

0
 
stephenlecomptejrAuthor Commented:
On the first one, I get no data loaded at startup...when I try to edit the Try stuff out... it ends up being an editing nightmare.

On the second one, I get the following image...
data-try-again.png
0
 
stephenlecomptejrAuthor Commented:
I meant to say on the first one, data never loads up... nevermind the editing nightmare.
0
 
databoksCommented:
If you could upload the database that Will be a great help. We are very close now. :)

0
 
stephenlecomptejrAuthor Commented:
Yeah!  Got It working.
This is the code I had to change... put back the ArrayList sequence and then have the datagrid source to that.
public void VisualData()
        {
            ArrayList sequence = new ArrayList();

            string sSQL = "";

            // had to adjust CHARINDEX('\\' 

            sSQL = "SELECT REPLACE(REVERSE(LEFT(REVERSE(DBName),CHARINDEX('\\', REVERSE(DBName),1)-1)), '.accdb', '') AS [Database Name], Access_USERS.[Full Name] as [User], Access_USERS.EXt as Ext, Access_USERS.CPU, substring(convert(varchar(20), Access_LOGGER.InDate, 9), 13, 5) as [Time In]";
            sSQL = sSQL + " FROM (Access_LOGGER INNER JOIN Access_DBLIST ON Access_LOGGER.fDBID = Access_DBLIST.ID) INNER JOIN Access_USERS ON Access_LOGGER.fUserID = Access_USERS.ID";
            sSQL = sSQL + " WHERE Access_LOGGER.OutDate Is Null";
            sSQL = sSQL + " ORDER BY [Time In]";


            SqlConnection sqlCon = null;
            string conn = "Data Source=EC-SQL;Initial Catalog=NEWEQ;User Id=NEWEQ;Password=n3w3@!;Connect Timeout=5";

            ////first test server
            //
            //sqlCon = new SqlConnection();
            //sqlCon.ConnectionString = conn;
            //try
            //{
            //    sqlCon.Open();
            //}
            //catch
            //{
            //    sqlCon.Close();
            //    sqlCon.Dispose();
            //    System.Environment.Exit(0);
            //    return;
            //}
            //sqlCon.Close();
            //sqlCon.Dispose();


            // do not put \\EC-SQL front of

            conn = "Data Source=EC-SQL;Initial Catalog=NEWEQ;User Id=NEWEQ;Password=n3w3@!;";

            
            sqlCon = new SqlConnection();
            sqlCon.ConnectionString = conn;
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = sqlCon;
            cmd.CommandText = sSQL;


            sqlCon.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                LogInfo m = new LogInfo();
                m.DBName = reader[0].ToString();
                m.User = reader[1].ToString();
                m.Ext = reader[2].ToString();
                m.CPU = reader[3].ToString();
                m.TimeIn = reader[4].ToString();

                //MessageBox.Show(reader[0].ToString());

                sequence.Add(m);
            }

            //This removes the Cross-Thread Exception.. You also have to Invoke the Object/Control it is created within another Thread.
            dgvLogger.BeginInvoke((MethodInvoker)delegate()
            {

                dgvLogger.DataSource = sequence;
                System.Windows.Forms.Application.DoEvents();

            });

            
            sqlCon.Close();



        }

Open in new window

0
 
stephenlecomptejrAuthor Commented:
However, I had to change the following code for void CheckForNewData()...
You'll note I had to remark out //this.Show(); because it caused the following error per Image:

I'll repost the files again.
void CheckForNewData()
        {
            while (true)
            {

                Thread.Sleep(60000);

                if (People_Logged_In() == true)
                {
                    
                    
                        dgvLogger.BeginInvoke((MethodInvoker)delegate()
                        {

                            VisualData();

                        });


                        //this.Show(); //Shows the form.. You can also use the ShowDialog(); The ShowDialog() is only good when using mulitple forms.


                        //this.Focus(); //Focus on the form 
                        
                    

                    
                }
                else
                {

                    //this.Hide();


                
                }

            }
        }

Open in new window

error-final.png
0
 
stephenlecomptejrAuthor Commented:
OK.  I've got that working with the following code change....
This is almost complete.

The only thing I have to test is when there are no records and it attempts to do a this.Hide();


if (People_Logged_In() == true)
                {
                    
                    
                        dgvLogger.BeginInvoke((MethodInvoker)delegate()
                        {

                            VisualData();
                            this.Show(); //Shows the form.. You can also use the ShowDialog(); The ShowDialog() is only good when using mulitple forms.
                            this.Focus(); //Focus on the form 

                        });


                        
                        
                    

                    
                }
                else
                {

                    this.Hide();


                
                }

Open in new window

0
 
stephenlecomptejrAuthor Commented:
Alright so this is the last thing its hanging up on now...
https://filedb.experts-exchange.com/incoming/ee-stuff/8103-Logger.zip
last-error.png
0
 
databoksCommented:
if (People_Logged_In() == true) 
                { 
                     
                     
                        dgvLogger.BeginInvoke((MethodInvoker)delegate() 
                        { 
 
                            VisualData(); 
                            this.Show(); //Shows the form.. You can also use the ShowDialog(); The ShowDialog() is only good when using mulitple forms. 
                            this.Focus(); //Focus on the form  
 
                        }); 
 
 
                         
                         
                     
 
                     
                } 
                else 
                { 
 
                this.BeginInvoke((MethodInvoker)delegate()
                    {
                        this.Hide();
                    });
 
                 
                }

Open in new window

0
 
databoksCommented:
You have to add the BeginInvoke Method. You should now be running.
0
 
stephenlecomptejrAuthor Commented:
YEA!!!!!   THANK YOU SO MUCH!!!!
0
 
stephenlecomptejrAuthor Commented:
databoks,

I also wanted your take since you've seen this project many times.
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_27051472.html

Anyway I can improve on the code?
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 24
  • 15
Tackle projects and never again get stuck behind a technical roadblock.
Join Now