I was making a program in Visual Basic 2010, and was wondering if a Progress bar could move accounting on a Timer? If yes, it would be very helpful for my current task.
try this something like this in VB.NET:
Do
Threading.Thread.Sleep(100)
ProgressBar1.PerformStep()
Loop Until ProgressBar1.Value >= ProgressBar1.Maximum
http://checktechno.blogspot.com/2013/03/example-progressbar-in-visual-basic.html
or in C#:
do {
System.Threading.Thread.Sleep(100);
ProgressBar1.PerformStep();
} while (!(ProgressBar1.Value >= ProgressBar1.Maximum));
where "sleep" is set as a constant at 100 ms. You just to dynamically set that value to your timer.
Related
I use Visual Studio 2017 to debug my code and leverage PerfTips to get the rough elapsed time of a function call.
But I just found big difference between perftips time and the time from StopWatch().
Example:
var sw=StopWatch();
sw.Start();
MyFunction();
sw.Stop();
I set break point before and after the MyFunction() call, PerfTips shows the elapsed time of MyFunction() call is around 260 ms.
But the sw.Elapsed.TotalMillionSeconds value is > 1000 ms. Why so big difference?
Anything wrong of my StopWatch usage or perftips?
BTW: I check the stopwatch time value in debugger mode, that is, set break point on sw.Stop, and read the value on debugger window. Is it incorrect way to get the accurate StopWatch() value?
For Each drow As DataGridViewRow In DgvItemList.Rows
drow.Cells("strSrNo").Value = drow.Index + 1
Next
I have more than 3500 records in DgvItemList. I just give to numbering to that records but it tool 9 to 10 minutes for that.
How to reduce this time ?
Two things. Each time you change the value, it could cause the DataGridView to update, so just before your loop, add
DgvItemList.SuspendLayout
and after the loop, add
DgvItemList.ResumeLayout
You could also change the loop to a Parallel.For loop, so your final code would be something like
DgvItemList.SuspendLayout
Parallel.For(0, DgvItemList.Rows.Count, Sub(index As Integer)
DgvItemList.Rows(index).Cells("strSrNo").Value = DgvItemList.Rows(index).Index + 1
End Sub)
DgvItemList.ResumeLayout
Try it with just the Suspend and Resume layout first. You may not get a vast amount of improvement from the parallelization. Worth a go though.
I am working on an application where there are read only screens.
To test whether the data is being fetched on screen load, i want to set some wait time till the screen is ready.
I am using python to record the actions. Is there a way to check the static text on the screen and set the time ?
You can simply use
snooze(time in s).
Example:
snooze(5)
If you want to wait for a certain object, use
waitForObject(":symbolic_name")
Example:
type(waitForObject(":Welcome.Button"), )
The problem is more complicated if your objects are created dynamically. As my app does. In this case, you should create a while function that waits until the object exists. Here, maybe this code helps you:
def whileObjectIsFalse(objectID):
# objectID = be the symbolic name of your object.
counter = 300
objectState = object.exists(objectID)
while objectState == False:
objectState = object.exists(objectID)
snooze(0.1)
counter -= 1
if counter == 0:
return False
snooze(0.2)
In my case, even if I use snooze(), doesn't work all the time, because in some cases i need to wait 5 seconds, in other 8 or just 2. So, presume that your object is not created and tests this for 30 seconds.
If your object is not created until then, then the code exits with False, and you can tests this to stop script execution.
If you're using python, you can use time.sleep() as well
If I am getting data from the database from start time to end time, during that time (of processing / querying), I want to display a progress bar (something like, “Processing, please wait”). How can I do this?
Steps of geting data from db:
app send query to db
db analyzes query and prepares result
db send result back to app
In most cases you cannot say how much time it will take, so instead of progress bar think about combination of:
hour glass mouse pointer
"please wait" in status bar
little animation (windmill, rotating gear wheels etc)
While its true that you cant tell how long the query is going to take, its possible to give your user and idea of the time lapsed/remaining. You use the progress bar control from your VB IDE. You then set its 'max' property to your query recordcount. As you iterate through the records increase the progress bars 'value' property. Here's an example; ('Rs' is an ADODB recordset)
ProgressBar1.Max = Rs.RecordCount - 1
For P = 0 To .RecordCount - 1
ProgressBar1.Value = P
'some process here
Rs.MoveNext
Next P
I wrote a VB.NET Windows Service, which works fine. I have only one issue with it. I want the service to execute on the half hour and top of the hour marks (e.g. 9:00, 9:30, 10:00, 10:30, 11:00, etc etc etc). I am using the following code:
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
Dim oCallBack As New TimerCallback(AddressOf TimedEvent)
oTimer = New System.Threading.Timer(oCallBack, Nothing, 300000, 300000)
EventLog.WriteEntry("CCFinalizeService has begun successfully." , _
System.Diagnostics.EventLogEntryType.Information)
End Sub
This code works, however, if the service starts at, say, 10:15, then it executes at 10:15, 10:45, 11:15, 11:45. How do I make it so it always executes on the 30 minute and top of the hour marks?
You could change it so that, at startup, it figures out the time required to go to a half hour increment based off the current time. Basically, your first timer would be <300000, then switch to every 300000.
Alternatively, you might want to consider using the Windows Task Scheduler instead of doing this as a service. The task scheduler lets you specify specific times to run an application.
You just need to modify the dueTime parameter in the Timer creation method
Dim now As Date = DateTime.Now
Dim dueTime As Integer ' milliseconds to the next half-hour
dueTime = 1800000 - (now.Minute Mod 30) * 60000 - now.Second * 1000 - now.Millisecond
oTimer = New System.Threading.Timer(oCallBack, Nothing, dueTime, 1800000)
Probably the easiest solution would be to test, at service startup, the current time, via the Date.Now property. You can then use a second timer to start the first timer, but set the Interval on the second timer to fire only at the next 1/2 hr or full hour mark.
Alternately, in your startup routine, have an infinite while loop that tests to see if the current time is on your mark. If not, System.Threading.Thread.Sleep(1000) and test again.
Good luck!
Maybe something like this??
If Now.Minute <> 0 Or Now.Minute <> 30 Then
Thread.Sleep((30 - Now.Minute) * 60 * 1000)
End If