maqskywalker
asked on
WPF application still running in task manager even after I close out my application
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.
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.
Do you have any polling loops or other threads in your application?
Try Application.Exit () or Perhaps you didn't close your SQL Connecrtion
ASKER
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.
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();
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The posters original Question has this.Close ();
So I assume he tried it and it didn't work ...
So I assume he tried it and it didn't work ...
It's possible that the Close() code in the original description was in the SECONDARY form?...
ASKER
Idle_Man your the man!
ASKER
I tried the suggestion that IDLE Mind gave in his code and that worked.
I changed this.Hide();
to this.Close();
and that worked.
I changed this.Hide();
to this.Close();
and that worked.