473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Help! My window application won't close.

I have a Window based application that shows up still running in the task
manager when I close it. It reaches the "this.close" statement and then it
stops at the "}" at the section of the following code after the
"Application.Run(new VMSMain());":
[STAThread]
static void Main()
{
Application.Run(new VMSMain());
}

I can't figure this one out at all. I would really appreciate some help
with this one.
Thanks, Alpha

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.IO;

namespace VMS
{
/// <summary>
/// Summary description for VMSMain.
/// </summary>
public class VMSMain : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private SqlConnection conDB;
private SqlCommand scUpdate, scGetPath;
private string strATSPath, NewATS;
private System.Windows.Forms.Label label1;

[STAThread]
static void Main()
{
Application.Run(new VMSMain());
}

public VMSMain()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//Connect to VMS DB
// string conStr = @"Server=DEVELOPMENT\NetSDK; user id=tis; password=tis;
database = VMS";
// string conStr = @"Server=WENDI; user id=tis; password=tis; database =
VMS";
string conStr = @"Server=Support\NetSDK; user id=tis; password=tis;
database = VMS";

conDB = new SqlConnection(conStr);

try
{
conDB.Open();
scUpdate = conDB.CreateCommand();
conDB.Close();
}
catch(Exception ex)
{
MessageBox.Show("Error connecting to the database server. VMS can't run
with out database connection and VMS will close. " + ex.ToString()+
"Please contact your support person.", "VMS - Database Open Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();

}
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(VMSMain));
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(80, 104);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(304, 23);
this.label1.TabIndex = 0;
this.label1.Text = "Updating database. Please wait..............";
//
// VMSMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.SystemColors.Control;
this.ClientSize = new System.Drawing.Size(496, 264);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this. Icon")));
this.MaximizeBox = false;
this.Name = "VMSMain";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScree n;
this.Text = "VMS - Updating Database ";
this.Closing += new
System.ComponentModel.CancelEventHandler(this.vmsM ain_Closing);
this.Load += new System.EventHandler(this.VMSMain_Load);
this.ResumeLayout(false);

}
#endregion

private void button1_Click(object sender, System.EventArgs e)
{
}

private void vmsMain_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
// conDB.Close();
}

private void VMSMain_Load(object sender, System.EventArgs e)
{
string[] ATSFiles;
bool NoFiles = false;
this.Show();
Cursor.Current = Cursors.WaitCursor;
// this.Show();
// MessageBox.Show("Updating VMS database. Please
wait.....................", "Updating");

//sdaUpdate = new SqlDataAdapter();
//GET THE ats file path from the DB
try
{
conDB.Open();
scGetPath = new SqlCommand("select LogFilePath from Admin", conDB);
strATSPath = scGetPath.ExecuteScalar().ToString();
strATSPath = strATSPath.Replace(@"\", @"\\");
conDB.Close();

}
catch(Exception ex)
{
MessageBox.Show("Error getting the ATS file path : " + ex.ToString()+
"Please contact your support person.", "VMS - ATS file path error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

}

//Get the latest ATS Access DB file name
try
{//@"C:\\VMS\\VMSDB"
ATSFiles = Directory.GetFiles(strATSPath, "Ats*Db.mdb");
if(ATSFiles.Length <= 0)
NoFiles = true;
else
{
NoFiles = false;
Array.Sort(ATSFiles);
NewATS= ATSFiles[ATSFiles.Length - 1];
NewATS = NewATS.Replace(@"\\", @"\");
}
}
catch(Exception ex)
{
MessageBox.Show("Error getting the ATS Access database files : " +
ex.ToString()+
"Please contact your support person.", "VMS - ATS files Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

}

if (!NoFiles)
{
try
{
//Begin Transaction
// SqlTransaction DbUpdateTransaction = conDB.BeginTransaction();
//
// scUpdate.Transaction = DbUpdateTransaction;

//Save the Previous readings
// scUpdate.CommandType = CommandType.StoredProcedure;
// scUpdate.CommandText = "SavePrevOdo";
// int row = scUpdate.ExecuteNonQuery();
conDB.Open();
int row;
//Insert new vehicle from the ATS Access database
scUpdate.CommandType = CommandType.Text;
scUpdate.CommandText = "INSERT INTO VehDetail(VName, LastOdometerDate,
LastOdometerReading)"+
" SELECT [d_RemoteName],CAST(MAX([d_DateTime]) AS DATETIME),
CAST(MAX([d_OdometerTenths]) AS INT(4))"+
" FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', '" +
NewATS + "';'Admin';'', DATA)"+
" WHERE [d_RemoteName] NOT IN(SELECT VNAME FROM VehDetail)"+
" GROUP BY [d_RemoteName]";
row = scUpdate.ExecuteNonQuery();

//Update the last date the odometer was read for each vehicle
scUpdate.CommandText = "UPDATE VehDetail SET VehDetail.LastOdometerDate
= (SELECT CAST(MAX([d_DateTime]) AS DATETIME)"+
" FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','"+
NewATS + "';'Admin';'', DATA)"+
" WHERE (d_RemoteName = VehDetail.VName))";
row = scUpdate.ExecuteNonQuery();

//Update the odometer at the last date the reading was taken
scUpdate.CommandText = "UPDATE VehDetail SET
VehDetail.LastOdometerReading ="+
" (SELECT CAST(MAX([d_OdometerTenths]) AS INT(4)) FROM
OPENROWSET('Microsoft.Jet.OLEDB.4.0','"+
NewATS + "';'Admin';'', DATA)"+
" WHERE (d_RemoteName = VehDetail.VName and DATEDIFF(SS,
CAST([d_DateTime] AS DATETIME), " +
"VehDetail.LastOdometerDate)=0))";
row = scUpdate.ExecuteNonQuery();

// DbUpdateTransaction.Commit();//Commit the transaction

}
catch(Exception ex)
{
MessageBox.Show("Error updating the database from ATS Access Database :
" + ex.ToString(), "Database Update Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

}
// finally
// {
//
// }

conDB.Close();

try
{
SqlCommand scRetMaint = conDB.CreateCommand();
scRetMaint.CommandType = CommandType.StoredProcedure;
scRetMaint.CommandText = "ReturnMaintDued";
conDB.Open();
scRetMaint.ExecuteNonQuery();
scRetMaint.CommandType = CommandType.Text;
scRetMaint.CommandText = "select count(*) from MaintenanceDued";
int rowCount = (int)scRetMaint.ExecuteScalar();
conDB.Close();
Cursor.Current = Cursors.Default;
if (rowCount > 0)
{
this.Hide();
Form frmMD = new MaintDued(conDB);
frmMD.ShowDialog();
this.Close();
}
else
{
MessageBox.Show("There is no maintenance dued for any vehicle at this
time.", "VMS - No Maintenance Dued",
MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Hide();
Form frmVeh = new vmsHome(conDB);
frmVeh.ShowDialog();
this.Close();
}
}//end try
catch(Exception ex)
{
MessageBox.Show("Error obtaining the count for number of vehicels dued
for maintenance." + ex.ToString(), "Database Update Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}//end catch
}// end if (!NoFiles)
else if (NoFiles)
{
MessageBox.Show("There is no ATS database files found in the directory
specified.", "VMS - No ATS database files",
MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Hide();
Form frmVeh = new vmsHome(conDB);
frmVeh.ShowDialog();
this.Close();
}//END else if (NoFiles)

//this.Close();
}
}
}

Nov 17 '05 #1
1 5471
Ok, I found the error. I put the "this.show" at the wrong place. It was at
the end of VMSMain(). I removed it and it works fine now.

"Alpha" wrote:
I have a Window based application that shows up still running in the task
manager when I close it. It reaches the "this.close" statement and then it
stops at the "}" at the section of the following code after the
"Application.Run(new VMSMain());":
[STAThread]
static void Main()
{
Application.Run(new VMSMain());
}

I can't figure this one out at all. I would really appreciate some help
with this one.
Thanks, Alpha

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.IO;

namespace VMS
{
/// <summary>
/// Summary description for VMSMain.
/// </summary>
public class VMSMain : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private SqlConnection conDB;
private SqlCommand scUpdate, scGetPath;
private string strATSPath, NewATS;
private System.Windows.Forms.Label label1;

[STAThread]
static void Main()
{
Application.Run(new VMSMain());
}

public VMSMain()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//Connect to VMS DB
// string conStr = @"Server=DEVELOPMENT\NetSDK; user id=tis; password=tis;
database = VMS";
// string conStr = @"Server=WENDI; user id=tis; password=tis; database =
VMS";
string conStr = @"Server=Support\NetSDK; user id=tis; password=tis;
database = VMS";

conDB = new SqlConnection(conStr);

try
{
conDB.Open();
scUpdate = conDB.CreateCommand();
conDB.Close();
}
catch(Exception ex)
{
MessageBox.Show("Error connecting to the database server. VMS can't run
with out database connection and VMS will close. " + ex.ToString()+
"Please contact your support person.", "VMS - Database Open Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();

}
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new
System.Resources.ResourceManager(typeof(VMSMain));
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(80, 104);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(304, 23);
this.label1.TabIndex = 0;
this.label1.Text = "Updating database. Please wait..............";
//
// VMSMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.SystemColors.Control;
this.ClientSize = new System.Drawing.Size(496, 264);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this. Icon")));
this.MaximizeBox = false;
this.Name = "VMSMain";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScree n;
this.Text = "VMS - Updating Database ";
this.Closing += new
System.ComponentModel.CancelEventHandler(this.vmsM ain_Closing);
this.Load += new System.EventHandler(this.VMSMain_Load);
this.ResumeLayout(false);

}
#endregion

private void button1_Click(object sender, System.EventArgs e)
{
}

private void vmsMain_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
// conDB.Close();
}

private void VMSMain_Load(object sender, System.EventArgs e)
{
string[] ATSFiles;
bool NoFiles = false;
this.Show();
Cursor.Current = Cursors.WaitCursor;
// this.Show();
// MessageBox.Show("Updating VMS database. Please
wait.....................", "Updating");

//sdaUpdate = new SqlDataAdapter();
//GET THE ats file path from the DB
try
{
conDB.Open();
scGetPath = new SqlCommand("select LogFilePath from Admin", conDB);
strATSPath = scGetPath.ExecuteScalar().ToString();
strATSPath = strATSPath.Replace(@"\", @"\\");
conDB.Close();

}
catch(Exception ex)
{
MessageBox.Show("Error getting the ATS file path : " + ex.ToString()+
"Please contact your support person.", "VMS - ATS file path error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

}

//Get the latest ATS Access DB file name
try
{//@"C:\\VMS\\VMSDB"
ATSFiles = Directory.GetFiles(strATSPath, "Ats*Db.mdb");
if(ATSFiles.Length <= 0)
NoFiles = true;
else
{
NoFiles = false;
Array.Sort(ATSFiles);
NewATS= ATSFiles[ATSFiles.Length - 1];
NewATS = NewATS.Replace(@"\\", @"\");
}
}
catch(Exception ex)
{
MessageBox.Show("Error getting the ATS Access database files : " +
ex.ToString()+
"Please contact your support person.", "VMS - ATS files Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

}

if (!NoFiles)
{
try
{
//Begin Transaction
// SqlTransaction DbUpdateTransaction = conDB.BeginTransaction();
//
// scUpdate.Transaction = DbUpdateTransaction;

//Save the Previous readings
// scUpdate.CommandType = CommandType.StoredProcedure;
// scUpdate.CommandText = "SavePrevOdo";
// int row = scUpdate.ExecuteNonQuery();
conDB.Open();
int row;
//Insert new vehicle from the ATS Access database
scUpdate.CommandType = CommandType.Text;
scUpdate.CommandText = "INSERT INTO VehDetail(VName, LastOdometerDate,
LastOdometerReading)"+
" SELECT [d_RemoteName],CAST(MAX([d_DateTime]) AS DATETIME),
CAST(MAX([d_OdometerTenths]) AS INT(4))"+
" FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', '" +
NewATS + "';'Admin';'', DATA)"+
" WHERE [d_RemoteName] NOT IN(SELECT VNAME FROM VehDetail)"+
" GROUP BY [d_RemoteName]";
row = scUpdate.ExecuteNonQuery();

//Update the last date the odometer was read for each vehicle
scUpdate.CommandText = "UPDATE VehDetail SET VehDetail.LastOdometerDate
= (SELECT CAST(MAX([d_DateTime]) AS DATETIME)"+
" FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0','"+
NewATS + "';'Admin';'', DATA)"+
" WHERE (d_RemoteName = VehDetail.VName))";
row = scUpdate.ExecuteNonQuery();

//Update the odometer at the last date the reading was taken
scUpdate.CommandText = "UPDATE VehDetail SET
VehDetail.LastOdometerReading ="+
" (SELECT CAST(MAX([d_OdometerTenths]) AS INT(4)) FROM
OPENROWSET('Microsoft.Jet.OLEDB.4.0','"+
NewATS + "';'Admin';'', DATA)"+
" WHERE (d_RemoteName = VehDetail.VName and DATEDIFF(SS,
CAST([d_DateTime] AS DATETIME), " +
"VehDetail.LastOdometerDate)=0))";
row = scUpdate.ExecuteNonQuery();

// DbUpdateTransaction.Commit();//Commit the transaction

}
catch(Exception ex)
{
MessageBox.Show("Error updating the database from ATS Access Database :
" + ex.ToString(), "Database Update Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);

}
// finally
// {
//
// }

conDB.Close();

try
{
SqlCommand scRetMaint = conDB.CreateCommand();
scRetMaint.CommandType = CommandType.StoredProcedure;
scRetMaint.CommandText = "ReturnMaintDued";
conDB.Open();
scRetMaint.ExecuteNonQuery();
scRetMaint.CommandType = CommandType.Text;
scRetMaint.CommandText = "select count(*) from MaintenanceDued";
int rowCount = (int)scRetMaint.ExecuteScalar();
conDB.Close();
Cursor.Current = Cursors.Default;
if (rowCount > 0)
{
this.Hide();
Form frmMD = new MaintDued(conDB);
frmMD.ShowDialog();
this.Close();
}
else
{
MessageBox.Show("There is no maintenance dued for any vehicle at this
time.", "VMS - No Maintenance Dued",
MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Hide();
Form frmVeh = new vmsHome(conDB);
frmVeh.ShowDialog();
this.Close();
}
}//end try
catch(Exception ex)

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Dave | last post by:
After following Microsofts admonition to reformat my system before doing a final compilation of my app I got many warnings/errors upon compiling an rtf file created in word. I used the Help...
4
by: Sarir Khamsi | last post by:
Is there a way to get help the way you get it from the Python interpreter (eg, 'help(dir)' gives help on the 'dir' command) in the module cmd.Cmd? I know how to add commands and help text to...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
6
by: d.warnermurray | last post by:
I am doing a project for school that involves creating help files for a html authoring tool. If you could help me with answers to some questions it would really help. 1. What tasks do you expect...
3
by: Colin J. Williams | last post by:
Python advertises some basic service: C:\Python24>python Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> With...
5
by: Steve | last post by:
I have written a help file (chm) for a DLL and referenced it using Help.ShowHelp My expectation is that a developer using my DLL would be able to access this help file during his development time...
4
by: Fred Flintstone | last post by:
This one baffles me. I'm using VS.Net 2005 and write desktop apps that need built in help. So logically, I figure maybe VS has a help system component built in so I search the help. Hey! ...
8
by: Mark | last post by:
I have loaded Visual Studio .net on my home computer and my laptop, but my home computer has an abbreviated help screen not 2% of the help on my laptop. All the settings look the same on both...
10
by: JonathanOrlev | last post by:
Hello everybody, I wrote this comment in another message of mine, but decided to post it again as a standalone message. I think that Microsoft's Office 2003 help system is horrible, probably...
1
by: trunxnirvana007 | last post by:
'UPGRADE_WARNING: Array has a new behavior. Click for more: 'ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?keyword="9B7D5ADD-D8FE-4819-A36C-6DEDAF088CC7"' 'UPGRADE_WARNING: Couldn't resolve...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.