473,385 Members | 1,676 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,385 software developers and data experts.

Winfprm Application Hangs on exit.


hi ,

I have a application which reads files, directory,and its version and
version information is written to text file.Its working fine if files
in directory are less but problem arises when no of file increases.
Its hangs and on pressing exit button it showing application not
responding..
Plz help me out
Here is da sample code::::::

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Collections.Specialized;
using System.Threading;

namespace FileVersionUitility
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lblSourceName;
private System.Windows.Forms.TextBox txtBFileInfo;
private System.Windows.Forms.Button btnVersion;
private System.Windows.Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
public string DirSourcePath ,DirDestinationPath;
// FileInfo[] files;
public static StreamWriter writer;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label lblDestinationPath;
private System.Windows.Forms.TextBox txtBDestPath;
private System.Windows.Forms.Button btn2Browse;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
private System.Windows.Forms.Button button2;
private System.ComponentModel.Container components = null;

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

//
// TODO: Add any constructor code after InitializeComponent call
//

}

/// <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()
{
this.lblSourceName = new System.Windows.Forms.Label();
this.txtBFileInfo = new System.Windows.Forms.TextBox();
this.btnVersion = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.button2 = new System.Windows.Forms.Button();
this.btn2Browse = new System.Windows.Forms.Button();
this.txtBDestPath = new System.Windows.Forms.TextBox();
this.lblDestinationPath = new System.Windows.Forms.Label();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// lblSourceName
//
this.lblSourceName.Location = new System.Drawing.Point(16, 48);
this.lblSourceName.Name = "lblSourceName";
this.lblSourceName.Size = new System.Drawing.Size(104, 23);
this.lblSourceName.TabIndex = 0;
this.lblSourceName.Text = "Source Path:";
this.lblSourceName.TextAlign =
System.Drawing.ContentAlignment.MiddleRight;
//
// txtBFileInfo
//
this.txtBFileInfo.AutoSize = false;
this.txtBFileInfo.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.txtBFileInfo.ForeColor = System.Drawing.Color.Wheat;
this.txtBFileInfo.Location = new System.Drawing.Point(120, 48);
this.txtBFileInfo.Name = "txtBFileInfo";
this.txtBFileInfo.ReadOnly = true;
this.txtBFileInfo.Size = new System.Drawing.Size(224, 24);
this.txtBFileInfo.TabIndex = 1;
this.txtBFileInfo.Text = "";
//
// btnVersion
//
this.btnVersion.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btnVersion.Location = new System.Drawing.Point(16, 144);
this.btnVersion.Name = "btnVersion";
this.btnVersion.Size = new System.Drawing.Size(104, 23);
this.btnVersion.TabIndex = 2;
this.btnVersion.Text = "Get File Version";
this.btnVersion.Click += new
System.EventHandler(this.btnVersion_Click);
//
// button1
//
this.button1.BackColor = System.Drawing.Color.OldLace;
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button1.Location = new System.Drawing.Point(360, 48);
this.button1.Name = "button1";
this.button1.TabIndex = 3;
this.button1.Text = "Browse";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// groupBox1
//
this.groupBox1.BackColor = System.Drawing.Color.OldLace;
this.groupBox1.Controls.Add(this.button2);
this.groupBox1.Controls.Add(this.btn2Browse);
this.groupBox1.Controls.Add(this.txtBDestPath);
this.groupBox1.Controls.Add(this.lblDestinationPat h);
this.groupBox1.Controls.Add(this.lblSourceName);
this.groupBox1.Controls.Add(this.txtBFileInfo);
this.groupBox1.Controls.Add(this.button1);
this.groupBox1.Controls.Add(this.btnVersion);
this.groupBox1.Font = new System.Drawing.Font("Microsoft Sans
Serif", 8.25F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.groupBox1.Location = new System.Drawing.Point(24, 48);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(472, 192);
this.groupBox1.TabIndex = 4;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "File Version Information";
//
// button2
//
this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.button2.Location = new System.Drawing.Point(360, 144);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(72, 23);
this.button2.TabIndex = 7;
this.button2.Text = "Exit";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// btn2Browse
//
this.btn2Browse.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
this.btn2Browse.Location = new System.Drawing.Point(360, 96);
this.btn2Browse.Name = "btn2Browse";
this.btn2Browse.TabIndex = 6;
this.btn2Browse.Text = "Browse";
this.btn2Browse.Click += new
System.EventHandler(this.btn2Browse_Click);
//
// txtBDestPath
//
this.txtBDestPath.AutoSize = false;
this.txtBDestPath.BorderStyle =
System.Windows.Forms.BorderStyle.FixedSingle;
this.txtBDestPath.Location = new System.Drawing.Point(120, 96);
this.txtBDestPath.Name = "txtBDestPath";
this.txtBDestPath.ReadOnly = true;
this.txtBDestPath.Size = new System.Drawing.Size(224, 24);
this.txtBDestPath.TabIndex = 5;
this.txtBDestPath.Text = "";
//
// lblDestinationPath
//
this.lblDestinationPath.Location = new System.Drawing.Point(16,
96);
this.lblDestinationPath.Name = "lblDestinationPath";
this.lblDestinationPath.Size = new System.Drawing.Size(104, 23);
this.lblDestinationPath.TabIndex = 4;
this.lblDestinationPath.Text = "Destination Path:";
this.lblDestinationPath.TextAlign =
System.Drawing.ContentAlignment.MiddleRight;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.BackColor = System.Drawing.Color.OldLace;
this.ClientSize = new System.Drawing.Size(528, 278);
this.Controls.Add(this.groupBox1);
this.Name = "Form1";
this.Text = "Form1";
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void btnVersion_Click(object sender, System.EventArgs e)
{

if(txtBFileInfo.Text=="")
{
MessageBox.Show("Source Path Missing!! Please Select The Directory
Path ","Error report",MessageBoxButtons.OK,MessageBoxIcon.Error) ;
}
else if(txtBDestPath.Text=="")
{
MessageBox.Show("Destination Path Missing!! Please Select The
Destination Path ","Error
report",MessageBoxButtons.OK,MessageBoxIcon.Error) ;
}

// FileVersionInfo myFileVersionInfo;
// DirectoryInfo root = new DirectoryInfo(DirSourcePath);
// DirectoryInfo[] dirs = root.GetDirectories();
// files = root.GetFiles();
// string fileName;
// foreach (FileInfo file in files)
// {
// fileName = file.FullName;
//// MessageBox.Show(file.FullName);
// myFileVersionInfo =
FileVersionInfo.GetVersionInfo(fileName);
//
// MessageBox.Show("File Name: " + file.Name + " Version
Info : "+ myFileVersionInfo.FileVersion);
// writer.WriteLine("File Name: " + file.Name + " Version
Info : "+ myFileVersionInfo.FileVersion);
//
// }
else
{
writer = new StreamWriter(DirDestinationPath);
//Create a Directory object using DirectoryInfo
// writer.WriteLine("File Name :" + " Version " + "Location");
DirectoryInfo dir =
new DirectoryInfo(DirSourcePath);
//Pass the Directory for displaying the contents
getDirsFiles(dir);
writer.Close();
MessageBox.Show("File is Created.......");
}

}

private void button1_Click(object sender, System.EventArgs e)
{
FolderBrowserDialog folderBrowserDialog = new
FolderBrowserDialog();
folderBrowserDialog.ShowDialog();
txtBFileInfo.Text = folderBrowserDialog.SelectedPath;
DirSourcePath =txtBFileInfo.Text;
}

public static void getDirsFiles(DirectoryInfo d)
{
//create an arrakmly of files using FileInfo object
FileInfo [] files;
//get all files for the current directory
files = d.GetFiles("*.*");
ArrayList arr = new ArrayList();
//iterate through the directory and print the files
foreach (FileInfo file in files)
{
//get details of each file using file object
String fileFullName = file.FullName;
String fileName = file.Name;
String fileSize = file.Length.ToString();
String fileExtension =file.Extension;
String fileCreated = file.LastWriteTime.ToString();
FileVersionInfo fileVersion =
FileVersionInfo.GetVersionInfo(fileFullName);
if(fileVersion.FileVersion!="")
{
arr.Add(fileName + " Version Details:: " +
fileVersion.FileVersion);
}
else
{
arr.Add(fileName + "Last Modified date :" +
file.LastWriteTime);
}
// arr.Add(fileName);
// arr.Add(fileVersion.FileVersion);
arr.Sort();

//
// Console.WriteLine(fileName + " " + fileSize +
// " " + fileExtension + " " + fileCreated);

// writer.WriteLine(fileName + " " + fileSize + " " +
fileExtension + " "
// + fileCreated + "Version :" + fileVersion.FileVersion);
// writer.WriteLine(fileName + " " +
fileVersion.FileVersion + " " + fileFullName);

}

foreach( string s in arr)
{
writer.WriteLine(s);
}
//get sub-folders for the current directory
DirectoryInfo [] dirs = d.GetDirectories("*.*");

//This is the code that calls
//the getDirsFiles (calls itself recursively)
//This is also the stopping point
//(End Condition) for this recursion function
//as it loops through until
//reaches the child folder and then stops.
foreach (DirectoryInfo dir in dirs)
{
// Console.WriteLine("--------->{0} ", dir.Name);
writer.WriteLine(dir.FullName);
writer.WriteLine();
getDirsFiles(dir);
}

}

private void btn2Browse_Click(object sender, System.EventArgs e)
{
saveFileDialog1.Filter = "Text files(*.txt)|*.txt";
saveFileDialog1.ShowDialog();
DirDestinationPath = saveFileDialog1.FileName;
txtBDestPath.Text = DirDestinationPath;
}

private void button2_Click(object sender, System.EventArgs e)
{
Application.Exit();
this.Close();
}

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

}
}
}

Jun 6 '07 #1
2 2408
Hi,

I would firstly suggest doing all the time consuming work in a
background thread.
You can easily use the BackgroundWorker component:
http://msdn2.microsoft.com/en-us/library/8xs8549b.aspx

If you don't want to do that, you should be able to pump the message
queue in the middle of the time consuming job. Insert an
Application.DoEvents() call in your foreach loop to pump the messages
(such as the button Click).

Feel free to ask any further questions.
Cheers,
Moty.

Jun 6 '07 #2
On Jun 6, 7:44 pm, Moty Michaely <Moty...@gmail.comwrote:
Hi,

I would firstly suggest doing all the time consuming work in a
background thread.
You can easily use the BackgroundWorker component:http://msdn2.microsoft.com/en-us/library/8xs8549b.aspx

If you don't want to do that, you should be able to pump the message
queue in the middle of the time consuming job. Insert an
Application.DoEvents() call in your foreach loop to pump the messages
(such as the button Click).

Feel free to ask any further questions.
Cheers,
Moty.
Thanx for da help,If possible can u Suggest with some code.

Jun 11 '07 #3

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

Similar topics

5
by: Richard Gutery | last post by:
G'day. Slight problem that has me perplexed. We have an ASP app running on Win2K IIS 5.1, devloped on WinXPpro. Up until the other day, the app worked without problems. Now, the app hangs on...
1
by: hype | last post by:
Hi, I interrupted running a sql batch file containing several insert statements. The db server stops responding to any commands and just hangs. The entries in the log file are as below, Any idea...
0
by: Laszlo Szijarto | last post by:
I have an app which moves around between a series of forms. I don't want to keep the forms open but hidden. I need to close them as I switch back and forth from one form to another. ...
2
by: Asad Khan | last post by:
I call the following method from my main form method: uploadThread = new Thread(new ThreadStart (this.doFTPUpload)); uploadThread.Name = "FTP Upload"; uploadThread.Start(); bool...
2
by: Robin Tucker | last post by:
Hiya, I have a problem with my application. It hangs around in memory after exiting (and the debugger thinks its still running; I am unable to "break" or "stop" execution). The main loop below...
12
by: JohnR | last post by:
I have narrowed a problem down to a simple example. A form with two buttons. One EXIT and one FBD. The exit button does an "END" to end the application. The FBD button does a...
9
by: a | last post by:
I already posted on this subject, but I have some more information that should make the issue clearer. Config: Apache 2.x, PHP 5.1.x, Windows XP Pro A php script processes a form. Inside this...
11
by: Grumpy Aero Guy | last post by:
I have created an app that makes use of the FolderBrowserDialog. Upon building the app, installing and running it, and invoking the form using the dialog, it hangs upon folder selection and goes...
5
by: junw2000 | last post by:
My program is about several thousands lines. It takes arguements from the command line. If no arguement is given, it should simply exist. Below is the architectureof main() : int main(int argc,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.