|
Exactly the same what I like to say. As its a different process, when the batch file execution get starts, it freezes all other process.
I have tried BackgroundWorker, but its not working in case of a batch file. It works for other simple processes.
Some one suggested to use Thread pool for this, I am trying with it.
|
|
|
|
|
What does your batch job do? Do you have some sample code to look at? It is probably best to use Threading.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
A progress bar should show progress, so the first thing to do is answer the question: how do you measure and quantify progress? what is going to provide this information?
it depends on the action(s) going on, of which you told us nothing.
|
|
|
|
|
Not a compulsion to use a progress bar, I could use Marquee instead of it. My only moto is to show something is running, to know the user that the system has not stopped working.
|
|
|
|
|
As far as I can see from the previous replies, the only valid way to use a ProgressBar would be to set its style to ProgressBarStyle.Marquee . This would indicate that something is happening, without the requirement to measure progress.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Ya,Thanks. I am satisfied with you. I dont have any problem for using marquee, but the question is how to implement this?
|
|
|
|
|
Add the ProgressBar to the Form , or a StatusProgressBar to the StatusBar , then in the Properties Window set the Style property to Marquee . The marquee effect should start right away, in the designer. So to turn it on and off at the right times change the Style property, in your code. To marquee to start it, and to block (and set value = maximum) to stop it.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks, But I dont have any problem in using Marquee. I know how to implement marquee, also with the help of toolStripProgressBar.
But the concern is, execution of a batch file is a diferent process, which will freezes other processes, like progressbar or toolStripProgressBar. Please guide me for that, if u can.
|
|
|
|
|
Ah, now I understand.
I'm afraid that I don't have a solution for that. I hope someone else is able to help you though.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi Henry,
No problem if u dont have a solution.
Thanks for ur contribution. I will definitely let u know, if I will get the solution of it.
Have a Nice Time.
---------------------
Regards,
Nitin Jenekar
|
|
|
|
|
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...
|
|
|
|
|
I want to get a copy of PDF file (from temporary internet files) which is opened on IE?
For this I was using
GetUrlCacheEntryInfo(String lpxaUrlName, IntPtr lpCacheEntryInfo, ref int lpdwCacheEntryInfoBufferSize);
this has been given in http://theagussantoso.blogspot.com/2008/11/get-temporary-internet-explorer-files.html
I get the error ERROR_FILE_NOT_FOUND when I was trying to get the realpath of the PDF file opened on browser?
How can I do this?
|
|
|
|
|
Hi all,
Which class within the .Net framework can I make use of to gain access to a remote client. I do have the user name and password, but require a class / method to gain access to the client PC.
I am receiving the following message: The system detected a possible attempt to compromise security. Please ensure that you can contact the server that authenticated you.
The only programmers that are better C# programmers, are those who look like this -> |
Programm3r
My Blog: ^_^
|
|
|
|
|
How to do unit test on private method and event handler? and how to test on method that does not return anything (void)? not using assert?
Can someone provide example?
Thank you!
|
|
|
|
|
|
Hi,
If i want to test on event handler, how can i initialize the value to?
fyi,i'm using unit testing features in vsts2008
For example,
private void txtDate_KeyPress(object sender, KeyPressEventArgs e)
{
// Numbers, slash only
if ((e.KeyChar >= '0' && e.KeyChar <= '9') || (int) e.KeyChar == 8 || e.KeyChar == '/')
{
e.Handled = false;
}
else if ((int) e.KeyChar == 13)
{
txtMiles.Focus();
}
else
{
e.Handled = true;
}
}
(auto generated when i create unit testing)
[Test Method]
public void txtDate_KeyPressTest()
{
frmMileage_Accessor target = new frmMileage_Accessor(); // TODO: Initialize to an appropriate value
object sender = null; // TODO: Initialize to an appropriate value
KeyPressEventArgs e = null; // TODO: Initialize to an appropriate value
target.txtDate_KeyPress(sender, e);
}
modified on Friday, April 24, 2009 3:25 AM
|
|
|
|
|
User interface testing is a thorny subject to say the least. If you really want real in depth testing of your user interface then my advice to you is to head for model view controller pattern. That pattern's main goal is the separation of concerns between the three entities that give it its name.
More generally speaking you don't need a method to return some value in order to unit test it.
One possible way of asserting a result in your case would be to make a simple unit test that says if input key char is 13 then make sure that after the txtDate_KeyPress is called the txtMiles has focus.
then another unit test would asset that if the key char is between this and that, e.handled is true. or false.
the way you have it set up:
[Test Method]
public void txtDate_KeyPressTest()
{
frmMileage_Accessor target = new frmMileage_Accessor(); // TODO: Initialize to an appropriate value
object sender = null; // TODO: Initialize to an appropriate value
KeyPressEventArgs e = null; // TODO: Initialize to an appropriate value
target.txtDate_KeyPress(sender, e);
}
i would do something like this:
[Test Method]
public void txtDate_KeyPressTest_Enter()
{
//Arrange
frmMileage_Accessor target = new frmMileage_Accessor();
object sender = null; // Does not matter since you're not using this parameter
KeyPressEventArgs args = new KeyPressEventArgs((char)13);
//Act
target.txtDate_KeyPress(sender, args);
//Assert
Assert.IsTrue(target.txtMiles.Focused);
}
[Test Method]
public void txtDate_KeyPressTest_Number()
{
//Arrange
frmMileage_Accessor target = new frmMileage_Accessor();
object sender = null; // Does not matter since you're not using this parameter
KeyPressEventArgs args = new KeyPressEventArgs((char)50);
//Act
target.txtDate_KeyPress(sender, args);
//Assert
Assert.IsFalse(args.Handled);
}
...
etc.
also, consider using Char.IsDigit(e.KeyChar) instead of e.KeyChar >= '0' && e.KeyChar <= '9'. it's a bit more clear
Regards
|
|
|
|
|
Thanks for previous answer. How about the following?
private void btnSave_Click(object sender, EventArgs e)
{
// Save mileage data
int i;
sfdFiles.Filter = "Files (*.gas)|*.gas";
sfdFiles.DefaultExt = "gas";
sfdFiles.Title = "Save Mileage File";
if (sfdFiles.ShowDialog() == DialogResult.OK)
{
StreamWriter sw = new StreamWriter(sfdFiles.FileName);
this.Text = "Gas Mileage-" + sfdFiles.FileName;
sw.WriteLine(numValues);
for (i = 0; i < numValues; i++)
{
sw.WriteLine(dates[i]);
sw.WriteLine(odometer[i]);
sw.WriteLine(gallons[i]);
}
sw.Close();
}
}
[TestMethod()]
public void btnSave_ClickTest()
{
frmMileage_Accessor target = new frmMileage_Accessor(); // TODO: Initialize to an appropriate value
object sender = null; // TODO: Initialize to an appropriate value
EventArgs e = null; // TODO: Initialize to an appropriate value
target.btnSave_Click(sender, e);
//Assert.Inconclusive("A method that does not return a value cannot be verified.");
}
I should initialize value to EventArgs? I have problem to assign value to EventArgs. How is the correct answer look like?
|
|
|
|
|
you don't use that variable in your method body so i guess null would be as fine as anything else
|
|
|
|
|
How m i going to test this kind of function?
private void saverecord()
{
OleDbConnection savecon = new OleDbConnection(constring);
OleDbCommand savecom = new OleDbCommand("insert into Employee_Details values (?,?,?)", savecon);
OleDbParameter param;
param = savecom.Parameters.Add("@empcode", OleDbType.VarChar, 10);
param.Value = txtcode.Text;
param = savecom.Parameters.Add("@empname", OleDbType.VarChar, 25);
param.Value = txtname.Text;
param = savecom.Parameters.Add("@empjoin", OleDbType.Date);
param.Value = DateTime.Now.ToShortDateString();
savecon.Open();
int rows = savecom.ExecuteNonQuery();
MessageBox.Show(rows.ToString() + "rows affected");
btnref.PerformClick();
savecon.Close();
}
[TestMethod()]
public void saverecordTest()
{
Form1_Accessor target = new Form1_Accessor(); // TODO: Initialize to an appropriate value
target.saverecord();
//Assert.Inconclusive("A method that does not return a value cannot be verified.");
}
|
|
|
|
|
Hi,
I am trying to enable password recovery, with the following settings:
<membership defaultprovider="SqlMembershipProvider" userisonlinetimewindow="15">
<providers>
<clear />
<add name="SqlMembershipProvider">
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="Gendac.Grintek.Abatis.DataAccess.Properties.Settings.PerimeterMainConnectionString"
applicationName="Abatis ClientUI"
enablePasswordRetrieval="true"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
passwordFormat="Encrypted"
minRequiredPasswordLength="3"
minRequiredNonalphanumericCharacters="0"/>
</add></providers>
</membership>
I know that I have to change the default machineKey, but I don't know how.
I think the machine key must be set in one of the files in C:\Windows\Microsoft.NET\Framework\v2.0.50727\CONFIG, but I don't know where and how.
Any help would be much appreciated.
This is my error:
You must specify a non-autogenerated machine key to store passwords in the encrypted format. Either specify a different passwordFormat, or change the machineKey configuration to use a non-autogenerated decryption key
Kind regards,
Higs
|
|
|
|
|
|
|
mostafatajamolian wrote: please give me code
Read the documentation[^] and try it yourself
I are troll
|
|
|
|
|
Well, you could do this using regular expressions, but personally I'd write a little function which iterates over the string and works it out (using StringBuilder) - that'd be quite a bit quicker.
Regards,
Rob Philpott.
|
|
|
|