[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

WPF application still running in task manager even after I close out my application

Posted on 2010-01-07
8
Medium Priority
?
2,456 Views
Last Modified: 2013-11-12
HI Experts,

I hava WPF application using C#.  The application queries sql server database and it works fine. When I close out my main application interface window, when i look at the processes running in task manager it is still running even after i close my application.

To close my main interface window I have a button that when clicked calls the close method


        private void button3_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

So when I click the button the program closes but it is still running in task manager.

Does anyone know the way to close my application so it is not showing in the task manager after i close my program.

Thanks.
0
Comment
Question by:maqskywalker
  • 3
  • 3
  • 2
8 Comments
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 26203999
Do you have any polling loops or other threads in your application?
0
 
LVL 12

Expert Comment

by:williamcampbell
ID: 26204242
Try Application.Exit () or Perhaps you didn't close your SQL Connecrtion
0
 
LVL 1

Author Comment

by:maqskywalker
ID: 26204416
Basically this is what's going on.

I have a WPF window called Window1.xaml and the code behind is Window1.xaml.cs

On this page I have 2 textboxes, one where the user enters the User ID and the other they enter Password.

Then they click a button to login.

After they click the button their user name and password are checked for those values in sql server, if it is a valid user id and password then they are taken to the main application interface window which in my application is called Window2.xaml
So when the a person logins in, Window1.xaml closes and the main interface Window2.xaml opens.
After I'm done using Window2.xaml and I close that window. That is when I notice that the application is still running in the task manager.
Here is the code for Window1.xaml.cs which is the code for my login Window.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data.OleDb;

namespace LoginApp1
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void btnLogIn_Click(object sender, RoutedEventArgs e)
        {
            //****Access the database and check for a user i.d. and password match.

            //****Create a connection to SQL Server.
            String SQLConnectionString = "PROVIDER=SQLOLEDB;DATA SOURCE=VenusDB;USER ID=MyDBUserId;PASSWORD=MyDBPassword;";
            OleDbConnection SQLPrimaryConnection = new OleDbConnection(SQLConnectionString);

            //****Open the connction.
            SQLPrimaryConnection.Open();

            //****Create a command. Pull data from the VenusDB system.
            string mySelectQuery = "SELECT * FROM VenusDB.DBO.IDENTIFICATION INNER JOIN VenusDB.DBO.PERSON_EMPLOYEE ON VenusDB.DBO.IDENTIFICATION.PERSON_KEY = VenusDB.DBO.PERSON_EMPLOYEE.PERSON_KEY WHERE VenusDB.DBO.PERSON_EMPLOYEE.HISTORICAL_RECORD_FLAG = 0 AND VenusDB.DBO.PERSON_EMPLOYEE.DEACTIVATED_FLAG = 0 AND VenusDB.DBO.PERSON_EMPLOYEE.PASSWORD = '" + txtPassword.Text.ToUpper() + "' AND VenusDB.DBO.IDENTIFICATION.IDENTIFICATION_CODE = 'VenusDB SECONDARY USER ID' AND VenusDB.DBO.IDENTIFICATION.IDENTIFICATION_NUMBER = '" + txtUser_ID.Text.ToUpper() + "'";


            OleDbCommand SQLCommand = new OleDbCommand(mySelectQuery, SQLPrimaryConnection);

            //****read the results of the command.
            OleDbDataReader SQLReader = SQLCommand.ExecuteReader();
            SQLReader.Read();

            try
            {

                //****This next line is used for testing.
                //MessageBox.Show(SQLReader["PERSON_KEY"].ToString());

                if (SQLReader["UNIT"].ToString() != "RECORDS")
                {
                    MessageBox.Show("Sorry, but you must be assigned to records before you can use this system.");
                }
                else
                {

                    //****Allow user access.

                    //****Open the main interface window.
                    Window2 Window2 = new Window2();
                    Window2.Show();

                    //****Close this form.
                    //frmLogIn newform = (frmLogIn)Application.OpenForms["frmLogIn"];
                    this.Hide();
                    //frmLogIn.ActiveForm.Close();
                }
            }
            catch
            {
                MessageBox.Show("Sorry, but you did not enter a valid user I.D. or password.");
            }

            //****Close the connection.
            SQLPrimaryConnection.Close();

        }

    }
}

Open in new window

0
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.

 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 26204600
It's still running because you only hid the main window.

Try this instead:
                if (SQLReader["UNIT"].ToString() != "RECORDS")
                {
                    MessageBox.Show("Sorry, but you must be assigned to records before you can use this system.");
                }
                else
                {
                    //****Allow user access.
                    this.Hide(); // hide the main window

                    //****Open the main interface window.
                    Window2 Window2 = new Window2();
                    // note that I'm using ShowDialog() instead of Show()...
                    // you could also subscribe to the FormClosed() event instead and use "this.Close()" from there
                    Window2.ShowDialog(); // <------ code STOPS here until "Window2" is closed!

                    //****Close this form.
                    this.Close();

                    // now the app should exit properly
                }

Open in new window

0
 
LVL 12

Expert Comment

by:williamcampbell
ID: 26204709
The posters  original Question has this.Close ();

So I assume he tried it and it didn't work ...
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 26204742
It's possible that the Close() code in the original description was in the SECONDARY form?...
0
 
LVL 1

Author Closing Comment

by:maqskywalker
ID: 31674218
Idle_Man your the man!
0
 
LVL 1

Author Comment

by:maqskywalker
ID: 26204829
I tried the suggestion that IDLE Mind gave in his code and that worked.

I changed this.Hide();
to this.Close();

and that worked.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This video teaches viewers about errors in exception handling.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month18 days, 14 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question