|
Isn't OnStart supposed to start a loop ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
the loop must start every x milliseconds. that's why it's located in the function that handles the timer. But the problem is partially resolved : I removed the MsgBox from the OnStart function and I moved the declaration of the timer outside of the same function. Now the service starts...and stops 5-10s after !...And it doesn't do what it should do...
Thanks for the answer
|
|
|
|
|
Not sure about this, but I don't think you can call MsgBox from a service unless it's been configured as 'Allow service to interact with the Desktop' or run under a specific user account.
"An eye for an eye only ends up making the whole world blind"
|
|
|
|
|
Hi!
Some thoughts/experiences with services:
1. You can't use message boxes (or any other form of user interaction) from services (unless you check the "allow service to interact with desktop" in the service manager, but that is very bad practice). Use the event log instead (see the example in the documentation for System.ServiceProcess.ServiceBase class in the framework class library). This is probably what causes your service to crash. Make sure neither your service nor the libraries you use rely on user interaction.
2. The System.Threading.Timer class is the right one to use in a service (the Windows Forms timers don't work - they rely on the window message pump, which doesn't exist in a service), but beware that it doesn't work like the Windows Forms timer: Among other things, it continues to fire events even when one is executing, so you have to do some synchronization (or disable and then reenable the timer) in Timer_Tick.
3. An exception on your worker thread (Timer_Tick) vanishes without a trace and the service doesn't stop because of it. Make Timer_Tick very small, containing only a try/catch block that logs any exceptions (and possibly does an Environment.FailFast if things look hopeless) and calls another member that does the actual work.
Hope this helped.
Peter the small turnip
(1) It Has To Work. --RFC 1925[^]
|
|
|
|
|
Hello, i was just wondering if anyone could supply me a bit of code that will automatically pin a program to the computers startup when the program is run for the first time. ....
Thank You, Jared7744
|
|
|
|
|
You'd want to put your shortcut in startup ( this is just in the file system ) or add the path to the Run key under windows in the registry.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi All
I am developing Outlook 2003 Addins using vb.net 2005. and i want to insert the some text in my outlook message at the current cursor position.
How can i do this.
Please suggest.
Thanx
Mitesh Khatri
khatrimitesh@hotmail.com
|
|
|
|
|
Hi,
I am using VB 2008 Express Edition and a beginner in the programming just learning. I own a Internet Cafe so i have created a program for the my cafe. I have a question that inseded of writing down the time in the register just click the start button for the speacifed computer and the timer should run counting and when i stop the stop button which are one button only the text must change near to the button the timer show from 00:00:00 to 01:34:21 hh:mm:ss.
|
|
|
|
|
So what is your question? How to use timers? Post your code and we will try to help.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Public Class System1
Dim timerstat As Boolean = False
Dim count As TimeSpan
Dim CHours As Boolean
Dim CMins As Boolean
Dim CSecs As Boolean
Dim CMSecs As Boolean
Private Sub btnSys1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSys1.Click
If timerstat = False Then
btnSys1.Text = "Stop"
Timer1.Start()
timerstat = True
ElseIf timerstat = True Then
btnSys1.Text = "Start"
Timer1.Stop()
timerstat = False
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
count = Timer1
If CSecs >= 10 Then
CMins = CMins + 1
CSecs = 0
Else
CSecs = CSecs + 1
End If
If CMins >= 60 Then
CHours = CHours + 1
CMins = 0
End If
If CHours < 10 Then CHours = "0"
If CMins < 10 Then CMins = "0"
If CSecs < 10 Then CSecs = "0"
lblTimer1.Text = count
End Sub
End Class
this what i gave the code to my program. The timer must count up as in this format hh:mm:ss as 00:34:05, 00:36:10 like this
|
|
|
|
|
And what does the code give you - apart from (I suspect) a lot of errors?
For example you cannot do arithmetic operations on boolean data types, they are true/false
One bit that will help is the string.format function
lblTimer.Text = string.format("{0}:{1}:{2}",hours,mins,secs)
Rethink your code, make sure it compiles and runs, then I may be able to help you, but I am not going to write it all for you.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Not and error message when i build. I get the error in the form in the lblTimer its showing false:false:false like that
|
|
|
|
|
Thats because your datatypes are boolean. Try using a numeric datatype
Bob
Ashfield Consultants Ltd
|
|
|
|
|
hi friends,
I am trying to fill a string array but i am getting an error as "Object Reference not set to an instance of an object"
Here is my sample code
dim str() as string
dim s as string
For i = 1 To 5
s = SomeMethod()
str(i) = s
Next
Here SomeMethod() is returning a string and i want to assign it to string array str(). Why i am getting above error? What i need to do?
Can anyone help me please.
Thanks,
Nagendra
|
|
|
|
|
nagendrathecoder wrote: dim str() as string
You are missing something.
|
|
|
|
|
You need to set the size of the array when you define it:
dim Str(5) as string
|
|
|
|
|
Thanks to both of u, now i got it correct. That was a silly mistake.
|
|
|
|
|
Hi,
I m using progressbar in my project to show how much process has completed but i wanna know how can i calculate the time which will consume in the process completion??
Hope u r getting wht i mean
Thanks
The Great Pleasure In Doing That Things That Other People Say U Can't By Doing This U Can Shut Their Mouth
|
|
|
|
|
~V~ wrote: how can i calculate the time which will consume in the process completion??
Depends on what you're doing. When I'm making a cup of coffee about 5 minutes (its a slow kettle)
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Actually i m using process in For loop
The Great Pleasure In Doing That Things That Other People Say U Can't By Doing This U Can Shut Their Mouth
|
|
|
|
|
Unless you know the depth of the for loop you cannot know the progress to completion. This why M$ has moved from the ever repeating progress bar that either repeats or sticks on 99% to the circular animated graphic.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks 4 reply
I m retriving data in dataset n after modifing it save back to new table
in this process i m using for loop n i wanna know how much time it will consume??
The Great Pleasure In Doing That Things That Other People Say U Can't By Doing This U Can Shut Their Mouth
|
|
|
|
|
~V~ wrote: how much time it will consume
Why - you can use the table.rows to set the max of the progressbar and increment by 1 each record that is processed.
As for time estimates there are way too many factors you will need to know to do the estimate. However a little thinking may lead you to something like this:
Guest the first number based on row count and estimated time of processing (you have already tested this during development)
check the duration of the first loop
multiply duration by rowcount
refine the estimate with each record processed till completed.
Waste of effort in my opinion but hey it's your time.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks a lot, its not time wasting its reqrirement of my project
The Great Pleasure In Doing That Things That Other People Say U Can't By Doing This U Can Shut Their Mouth
|
|
|
|
|
Well, if a simple count as Mycroft suggests isn't good enough you are going to have a problem - different processors, memory etc etc. You could time the 1st iteration and use that combined with the number of records to give a rough approximation I expect.
Bob
Ashfield Consultants Ltd
|
|
|
|