Click here to Skip to main content
15,888,454 members
Home / Discussions / C#
   

C#

 
GeneralRe: Show the progress bar while executing a batch file in C# windows forms? Pin
Nitin Jenekar23-Apr-09 19:32
Nitin Jenekar23-Apr-09 19:32 
AnswerRe: Show the progress bar while executing a batch file in C# windows forms? Pin
Henry Minute23-Apr-09 5:06
Henry Minute23-Apr-09 5:06 
GeneralRe: Show the progress bar while executing a batch file in C# windows forms? Pin
Nitin Jenekar23-Apr-09 19:37
Nitin Jenekar23-Apr-09 19:37 
GeneralRe: Show the progress bar while executing a batch file in C# windows forms? Pin
Henry Minute23-Apr-09 23:51
Henry Minute23-Apr-09 23:51 
GeneralRe: Show the progress bar while executing a batch file in C# windows forms? Pin
Nitin Jenekar24-Apr-09 2:26
Nitin Jenekar24-Apr-09 2:26 
GeneralRe: Show the progress bar while executing a batch file in C# windows forms? Pin
Henry Minute24-Apr-09 2:37
Henry Minute24-Apr-09 2:37 
GeneralRe: Show the progress bar while executing a batch file in C# windows forms? Pin
Nitin Jenekar24-Apr-09 2:47
Nitin Jenekar24-Apr-09 2:47 
AnswerRe: Show the progress bar while executing a batch file in C# windows forms? Pin
Nitin Jenekar20-May-09 0:35
Nitin Jenekar20-May-09 0:35 
Hi Friends,
Finally I have implemented this using ThreadPool class.
We can process the jobs in parallel using thread pools. I have used the built-in framework ThreadPool class, for running the batch process and updating a ProgressBar.
Here I used the marquee style of ProgressBar, as its not possible to count the time required for executing the batch file in advance(as the size/functionality of batch file may vary).

Following is the code for the reference:

public partial class Upload : Form
{
// Delegate that runs on the UI thread to update the progress bar.
public delegate void ProgressBarDelegate();

//statusFlag for the functioning of Progress bar
int statusFlag = 0;

// On buttom click, launch a new thread
private void btnRun_Click(object sender, EventArgs e)
{
progressBar1.Visible = true;
ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessFile));
}

private void ProcessFile(object a)
{

#region execute a batch file

//Reading the location of batch file

filePath = txtPath.Text + "\\Upload.bat";
try
{
Process proc = new Process();
ProcessStartInfo psi = new ProcessStartInfo();
proc.StartInfo.FileName = filePath;
proc.StartInfo.WorkingDirectory = txtPath.Text;
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardInput = true;
proc.StartInfo.RedirectStandardOutput = true;
proc.StartInfo.RedirectStandardError = true;
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;

//Start the process
string startTime = DateTime.Now.ToString();
proc.Start();

//Close the process
proc.Close();

}
catch (Exception ex)
{
//Handles the exception
return;
}

#endregion

MessageBox.Show("Process completed !");

//Changing the flag for stopping the progress bar
statusFlag = 1;

#region Invoke the ProgressBarDelegate
try
{
// Invoke the delegate on the form.
this.Invoke(new ProgressBarDelegate(IncrementBar));
}
catch
{
//Handles the exception
return;
}
#endregion

}

private void IncrementBar()
{
if (statusFlag == 1)
{
progressBar1.Visible = false;
}
}
}


Enjoy the programming... Wink | ;)
QuestionERROR_FILE_NOT_FOUND while using GetUrlCacheEntryInfo() ? Pin
svt gdwl23-Apr-09 0:57
svt gdwl23-Apr-09 0:57 
QuestionNetwork Authority Pin
Programm3r22-Apr-09 23:50
Programm3r22-Apr-09 23:50 
Questionvsts 2008 unit testing Pin
BabyOreo22-Apr-09 22:44
BabyOreo22-Apr-09 22:44 
AnswerRe: vsts 2008 unit testing Pin
smurariu23-Apr-09 3:46
smurariu23-Apr-09 3:46 
GeneralRe: vsts 2008 unit testing [modified] Pin
BabyOreo23-Apr-09 21:04
BabyOreo23-Apr-09 21:04 
GeneralRe: vsts 2008 unit testing Pin
smurariu24-Apr-09 4:11
smurariu24-Apr-09 4:11 
GeneralRe: vsts 2008 unit testing Pin
BabyOreo26-Apr-09 22:47
BabyOreo26-Apr-09 22:47 
GeneralRe: vsts 2008 unit testing Pin
smurariu27-Apr-09 6:09
smurariu27-Apr-09 6:09 
GeneralRe: vsts 2008 unit testing Pin
BabyOreo28-Apr-09 17:35
BabyOreo28-Apr-09 17:35 
QuestionMachineKey configuration + Password recovery Pin
bonkers12322-Apr-09 22:38
bonkers12322-Apr-09 22:38 
AnswerRe: MachineKey configuration + Password recovery Pin
bonkers12322-Apr-09 23:32
bonkers12322-Apr-09 23:32 
Question[Message Deleted] Pin
mostafatajamolian22-Apr-09 22:36
mostafatajamolian22-Apr-09 22:36 
AnswerRe: replace text Pin
Eddy Vluggen22-Apr-09 22:47
professionalEddy Vluggen22-Apr-09 22:47 
AnswerRe: replace text Pin
Rob Philpott22-Apr-09 22:48
Rob Philpott22-Apr-09 22:48 
AnswerRe: replace text Pin
musefan22-Apr-09 23:33
musefan22-Apr-09 23:33 
AnswerRe: replace text Pin
OriginalGriff23-Apr-09 2:06
mveOriginalGriff23-Apr-09 2:06 
GeneralRe: replace text Pin
Eddy Vluggen23-Apr-09 6:19
professionalEddy Vluggen23-Apr-09 6:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.