473,587 Members | 2,225 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
using System.Diagnost ics;
using System.IO;
using System.Collecti ons.Specialized ;
using System.Threadin g;

namespace FileVersionUiti lity
{
/// <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 ,DirDestination Path;
// FileInfo[] files;
public static StreamWriter writer;
private System.Windows. Forms.GroupBox groupBox1;
private System.Windows. Forms.Label lblDestinationP ath;
private System.Windows. Forms.TextBox txtBDestPath;
private System.Windows. Forms.Button btn2Browse;
private System.Windows. Forms.SaveFileD ialog saveFileDialog1 ;
private System.Windows. Forms.Button button2;
private System.Componen tModel.Containe r components = null;

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

//
// TODO: Add any constructor code after InitializeCompo nent call
//

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
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 InitializeCompo nent()
{
this.lblSourceN ame = new System.Windows. Forms.Label();
this.txtBFileIn fo = 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.txtBDestPa th = new System.Windows. Forms.TextBox() ;
this.lblDestina tionPath = new System.Windows. Forms.Label();
this.saveFileDi alog1 = new System.Windows. Forms.SaveFileD ialog();
this.groupBox1. SuspendLayout() ;
this.SuspendLay out();
//
// lblSourceName
//
this.lblSourceN ame.Location = new System.Drawing. Point(16, 48);
this.lblSourceN ame.Name = "lblSourceName" ;
this.lblSourceN ame.Size = new System.Drawing. Size(104, 23);
this.lblSourceN ame.TabIndex = 0;
this.lblSourceN ame.Text = "Source Path:";
this.lblSourceN ame.TextAlign =
System.Drawing. ContentAlignmen t.MiddleRight;
//
// txtBFileInfo
//
this.txtBFileIn fo.AutoSize = false;
this.txtBFileIn fo.BorderStyle =
System.Windows. Forms.BorderSty le.FixedSingle;
this.txtBFileIn fo.ForeColor = System.Drawing. Color.Wheat;
this.txtBFileIn fo.Location = new System.Drawing. Point(120, 48);
this.txtBFileIn fo.Name = "txtBFileIn fo";
this.txtBFileIn fo.ReadOnly = true;
this.txtBFileIn fo.Size = new System.Drawing. Size(224, 24);
this.txtBFileIn fo.TabIndex = 1;
this.txtBFileIn fo.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.EventHan dler(this.btnVe rsion_Click);
//
// button1
//
this.button1.Ba ckColor = System.Drawing. Color.OldLace;
this.button1.Fl atStyle = System.Windows. Forms.FlatStyle .Popup;
this.button1.Lo cation = new System.Drawing. Point(360, 48);
this.button1.Na me = "button1";
this.button1.Ta bIndex = 3;
this.button1.Te xt = "Browse";
this.button1.Cl ick += new System.EventHan dler(this.butto n1_Click);
//
// groupBox1
//
this.groupBox1. BackColor = System.Drawing. Color.OldLace;
this.groupBox1. Controls.Add(th is.button2);
this.groupBox1. Controls.Add(th is.btn2Browse);
this.groupBox1. Controls.Add(th is.txtBDestPath );
this.groupBox1. Controls.Add(th is.lblDestinati onPath);
this.groupBox1. Controls.Add(th is.lblSourceNam e);
this.groupBox1. Controls.Add(th is.txtBFileInfo );
this.groupBox1. Controls.Add(th is.button1);
this.groupBox1. Controls.Add(th is.btnVersion);
this.groupBox1. Font = new System.Drawing. Font("Microsoft Sans
Serif", 8.25F, System.Drawing. FontStyle.Bold,
System.Drawing. GraphicsUnit.Po int, ((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.Fl atStyle = System.Windows. Forms.FlatStyle .Popup;
this.button2.Lo cation = new System.Drawing. Point(360, 144);
this.button2.Na me = "button2";
this.button2.Si ze = new System.Drawing. Size(72, 23);
this.button2.Ta bIndex = 7;
this.button2.Te xt = "Exit";
this.button2.Cl ick += new System.EventHan dler(this.butto n2_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.EventHan dler(this.btn2B rowse_Click);
//
// txtBDestPath
//
this.txtBDestPa th.AutoSize = false;
this.txtBDestPa th.BorderStyle =
System.Windows. Forms.BorderSty le.FixedSingle;
this.txtBDestPa th.Location = new System.Drawing. Point(120, 96);
this.txtBDestPa th.Name = "txtBDestPa th";
this.txtBDestPa th.ReadOnly = true;
this.txtBDestPa th.Size = new System.Drawing. Size(224, 24);
this.txtBDestPa th.TabIndex = 5;
this.txtBDestPa th.Text = "";
//
// lblDestinationP ath
//
this.lblDestina tionPath.Locati on = new System.Drawing. Point(16,
96);
this.lblDestina tionPath.Name = "lblDestination Path";
this.lblDestina tionPath.Size = new System.Drawing. Size(104, 23);
this.lblDestina tionPath.TabInd ex = 4;
this.lblDestina tionPath.Text = "Destinatio n Path:";
this.lblDestina tionPath.TextAl ign =
System.Drawing. ContentAlignmen t.MiddleRight;
//
// Form1
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.BackColor = System.Drawing. Color.OldLace;
this.ClientSize = new System.Drawing. Size(528, 278);
this.Controls.A dd(this.groupBo x1);
this.Name = "Form1";
this.Text = "Form1";
this.groupBox1. ResumeLayout(fa lse);
this.ResumeLayo ut(false);

}
#endregion

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

if(txtBFileInfo .Text=="")
{
MessageBox.Show ("Source Path Missing!! Please Select The Directory
Path ","Error report",Message BoxButtons.OK,M essageBoxIcon.E rror);
}
else if(txtBDestPath .Text=="")
{
MessageBox.Show ("Destinatio n Path Missing!! Please Select The
Destination Path ","Error
report",Message BoxButtons.OK,M essageBoxIcon.E rror);
}

// FileVersionInfo myFileVersionIn fo;
// DirectoryInfo root = new DirectoryInfo(D irSourcePath);
// DirectoryInfo[] dirs = root.GetDirecto ries();
// files = root.GetFiles() ;
// string fileName;
// foreach (FileInfo file in files)
// {
// fileName = file.FullName;
//// MessageBox.Show (file.FullName) ;
// myFileVersionIn fo =
FileVersionInfo .GetVersionInfo (fileName);
//
// MessageBox.Show ("File Name: " + file.Name + " Version
Info : "+ myFileVersionIn fo.FileVersion) ;
// writer.WriteLin e("File Name: " + file.Name + " Version
Info : "+ myFileVersionIn fo.FileVersion) ;
//
// }
else
{
writer = new StreamWriter(Di rDestinationPat h);
//Create a Directory object using DirectoryInfo
// writer.WriteLin e("File Name :" + " Version " + "Location") ;
DirectoryInfo dir =
new DirectoryInfo(D irSourcePath);
//Pass the Directory for displaying the contents
getDirsFiles(di r);
writer.Close();
MessageBox.Show ("File is Created......." );
}

}

private void button1_Click(o bject sender, System.EventArg s e)
{
FolderBrowserDi alog folderBrowserDi alog = new
FolderBrowserDi alog();
folderBrowserDi alog.ShowDialog ();
txtBFileInfo.Te xt = folderBrowserDi alog.SelectedPa th;
DirSourcePath =txtBFileInfo.T ext;
}

public static void getDirsFiles(Di rectoryInfo 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.ToS tring();
String fileExtension =file.Extension ;
String fileCreated = file.LastWriteT ime.ToString();
FileVersionInfo fileVersion =
FileVersionInfo .GetVersionInfo (fileFullName);
if(fileVersion. FileVersion!="" )
{
arr.Add(fileNam e + " Version Details:: " +
fileVersion.Fil eVersion);
}
else
{
arr.Add(fileNam e + "Last Modified date :" +
file.LastWriteT ime);
}
// arr.Add(fileNam e);
// arr.Add(fileVer sion.FileVersio n);
arr.Sort();

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

// writer.WriteLin e(fileName + " " + fileSize + " " +
fileExtension + " "
// + fileCreated + "Version :" + fileVersion.Fil eVersion);
// writer.WriteLin e(fileName + " " +
fileVersion.Fil eVersion + " " + fileFullName);

}

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

//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.WriteLi ne("--------->{0} ", dir.Name);
writer.WriteLin e(dir.FullName) ;
writer.WriteLin e();
getDirsFiles(di r);
}

}

private void btn2Browse_Clic k(object sender, System.EventArg s e)
{
saveFileDialog1 .Filter = "Text files(*.txt)|*. txt";
saveFileDialog1 .ShowDialog();
DirDestinationP ath = saveFileDialog1 .FileName;
txtBDestPath.Te xt = DirDestinationP ath;
}

private void button2_Click(o bject sender, System.EventArg s e)
{
Application.Exi t();
this.Close();
}

private void button3_Click(o bject sender, System.EventArg s e)
{

}
}
}

Jun 6 '07 #1
2 2433
Hi,

I would firstly suggest doing all the time consuming work in a
background thread.
You can easily use the BackgroundWorke r 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.DoE vents() 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 BackgroundWorke r 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.DoE vents() 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
1662
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 an FSO request. I've inlcuded the relevant code below for referrence. Basically, the code will check to see if a dir exists (CALLOUT 1), then
1
1785
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 what could be happening or any troubleshooting tips ? ------------------ 2004-03-06-11.51.16.095814 Instance:db2inst1 Node:000...
0
1159
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. Unfortunately, if I start up my app with Application.Run(new formLogin()), for example, as soon as the formLogin gets closed, the whole app exits. Yet, if I...
2
10519
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 threadTerminatedGood = uploadThread.Join(client.transmissionTimeout*60*1000); if (!threadTerminatedGood) { throw new Exception("The upload thread was interrupted...
2
1527
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 shows my "main" function. When the main form is closed, this function is exited, so the "hang" occurs in code outside of my control. I am using...
12
5854
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 FolderBrowserDialog and nothing else. When I start the application and hit EXIT everything works fine. However if it display the FBD box (even if I don't pick a...
9
2288
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 script I call exec to run a Windows process. If I press the submit button on the form repeatedly, exec starts and exit the process several times,...
11
3001
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 "not responding" Upon debugging, it hangs as well upon executing the line that extracts the selected folder without further explanation. All looks...
5
5360
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, char *argv) { if( argc == 1 ) { cout << "NO ARGUEMENT"<<endl;
0
7843
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8205
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8339
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7967
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6619
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.