|
Thanks, Luc, you saved me from some code typing
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
When code does not feel good, I'd prefer to remove some, rather than add some.
|
|
|
|
|
I agree
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
i hav window service app. when i start the method call by onstart method fire only once
|
|
|
|
|
The OnStart[^] method only fires once, so any calls in it will also only be fired once. Start a thread in OnStart if you want something to loop. (Don't do a loop in OnStart as the service won't finish starting until the loop completes.)
|
|
|
|
|
i did not do a loop . already have a loop please look at the code
Public Class AuthorLogService
Public diamondEmail, Hostname, DomainName, diamondEmailBox, diamondUserName, diamondPassword, Protocol, ftpUser, diamondEmail1, diamondEmail2, diamondEmail3, ftpLogDirectory As String
Public UserName, Password, emailName, pfcAccount, pfaAccount, pfaName, ccemail, bccmail, logFullPath, dbFullPath As String
Public timeinterval As Int32 = 12000
Public connectionstring As String
Public con As SqlConnection
Public command As SqlCommand
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.
Const iTIME_INTERVAL As Integer = 120000 ' 2 *60 seconds.
Dim oTimer As System.Threading.Timer
'Dim con As New System.Data.SqlClient.SqlConnection("server=PRGLAP11;database = Diamonddb ;uid=sa;pwd=eb")
connectionstring = My.Settings.connectionstring
con = New SqlConnection(connectionstring)
'Dim command As SqlCommand = New SqlCommand("", con)
Command = New SqlCommand("", con)
Command.CommandType = CommandType.StoredProcedure
command.CommandText = "getHost"
Dim adp As SqlDataAdapter = New SqlDataAdapter(command)
Dim dt As New DataTable
adp.Fill(dt)
Dim dtr As DataTableReader = dt.CreateDataReader
While dtr.Read
Hostname = dtr.GetString(1)
DomainName = dtr.GetString(2)
diamondEmail = dtr.GetString(3)
diamondUserName = dtr.GetString(4)
Protocol = dtr.GetString(5)
diamondPassword = dtr.GetString(6)
ftpLogDirectory = dtr.GetString(7) & "\" & "ex" & Format(Today.Date, "yyMMdd") & ".log"
'timeinterval = dtr.GetInt32(8) * 6000
'System.IO.File.AppendAllText("C:\test2.txt", Hostname)
'System.IO.File.AppendAllText("C:\test2.txt", DomainName)
'System.IO.File.AppendAllText("C:\test2.txt", diamondEmailBox)
'File.AppendAllText("c:\test3.txt", "these are ")
End While
dtr.Close()
Dim command1 As SqlCommand = New SqlCommand("", con)
command1.CommandType = CommandType.StoredProcedure
command1.CommandText = "getdiamondmails"
Dim adp1 As New SqlDataAdapter(command1)
Dim dt1 As New DataTable
adp1.Fill(dt1)
Dim dtr1 As DataTableReader = dt1.CreateDataReader
While dtr1.Read
diamondEmail1 = dtr1.GetString(1)
diamondEmail2 = dtr1.GetString(2)
diamondEmail3 = dtr1.GetString(3)
'System.IO.File.AppendAllText("C:\test2.txt", diamondEmail1)
'System.IO.File.AppendAllText("C:\test2.txt", diamondEmail2)
'System.IO.File.AppendAllText("C:\test2.txt", diamondEmail3)
End While
dtr1.Close()
System.IO.File.AppendAllText("C:\henry.txt", "AuthorLogService has been started at " & Now.ToString)
Dim tDelegate As Threading.TimerCallback = AddressOf EventAction
oTimer = New System.Threading.Timer(tDelegate, Me, 0, iTIME_INTERVAL)
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
End Sub
'this eventaction is fired once
Public Sub EventAction(ByVal sender As Object)
'Dim s1, s2, s3 As String
System.IO.File.AppendAllText("C:\test3.txt", "AuthorLogService fires EventAction at " & Now.ToString())
System.IO.File.AppendAllText("C:\test2.txt", Protocol)
System.IO.File.AppendAllText("C:\test2.txt", timeinterval)
System.IO.File.AppendAllText("C:\test2.txt", ftpLogDirectory)
End Sub
End Class
|
|
|
|
|
My guess is the System.Threading.Timer is not keeping the service running, as opposed to a thread[^] which will keep the service running.
The last time I made a service, I created a thread in the OnStart event and I put the code for what I wanted the service to do in the thread. The service would keep running until that thread was terminated.
Someone else feel free to correct me if I am wrong.
|
|
|
|
|
I'm in need of a quick answer to a problem. I am trying to parse a tab delimited file for the purpose of feed it to a check printer. I am using a stream reader and the issue is that the reader is dropping the first char of each line. Here's the code:
Do While strRead.Read <> strRead.EndOfStream
strTest = strRead.ReadLine
strWrite = strTest.Replace("""", "")
ListBox1.Items.Add(strWrite)
Loop
Can anybody help?
Thanks
|
|
|
|
|
ok I found a solution this method from the MSDN worked. I'm not sure why at this point. When I figure it out I'll let you know.
Using sr As StreamReader = New StreamReader("TestFile.txt")
Dim line As String
Do
line = sr.ReadLine()
Console.WriteLine(Line)
Loop Until line Is Nothing
sr.Close()
End Using
|
|
|
|
|
Hi,
I would guess strRead.Read really reads something, maybe one byte or so, and you
don't process it. Did you care looking at the documentation of the classes you use?
|
|
|
|
|
Come on now read documentation? Who does that? No your right under the pressure of an angry ap clerk I did not research class well. Since I have been doing this since vb3 you'd think I'd know beter by now.
|
|
|
|
|
jhoga wrote: Come on now read documentation? Who does that?
Real people.
jhoga wrote: the pressure of an angry ap clerk
Well, let's see the angry ap clerk do a better job, which I doubt
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Luc Pattyn wrote: Did you care looking at the documentation of the classes you use?
He obviously didn't and can't believe the attitude he gave you in his reply about reading documentation.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Paul Conrad wrote: He obviously didn't and can't believe the attitude he gave you in his reply about reading documentation.
Did you get that he was poking fun at himself in his reply?
Did you see the "Red face" emoticon?
He wasn't giving any attitude. He was saying "Doh!".
|
|
|
|
|
RCoate wrote: Did you get that he was poking fun at himself in his reply?
Looking back at it, yes.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
strRead.Read reads the first character of every line.
do while not str.Read.EndOfStream
...
loop
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios
Discounted or Free Software for Students:
DreamSpark - downloads.channel8.msdn.com
MSDN Academic Alliance - www.msdnaa.com
|
|
|
|
|
i have winservice project. call a method to append to a fire at 60 second interval. i notice that it append twice and student. if i insert to data base it inserts one do the sevice is still runnin
|
|
|
|
|
Hi,
When I run a DOS command line program it will work on a file that is located in the root of C:\ but if I try to run it on a file on my desktop nothing happens. Is there any way to get this to work.
|
|
|
|
|
Try this
Process.Start("cmd")
Vote the answer if it is helpful
|
|
|
|
|
This is the code I am using
'myProcess.StartInfo.FileName = "C:\Program Files\PDFcheck\pdffonts.exe " 'Full pathname to including file name
'myProcess.StartInfo.Arguments = filename ' If the program takes args as string
'myProcess.StartInfo.CreateNoWindow = True ' Does not create a window DOS program
'myProcess.StartInfo.UseShellExecute = False ' Must be false to redirect output
'myProcess.StartInfo.RedirectStandardOutput = True
'myProcess.Start() ' Start the DOS program
'myProcess.WaitForExit() ' Wait until it completes before moving on
'prgOutput = myProcess.StandardOutput.ReadToEnd ' Get the DOS output
'pdffonts = prgOutput
'f.Close()
|
|
|
|
|
include the full path to your program.
Greetings from Germany
|
|
|
|
|
Could it be that the filepath you are supplying contains spaces? If it is a dos program, they generally don't support spaces within filenames, and "c:\documents and settings\user\desktop" does contain spaces. You could try:
c:\docume~1\user\desktop\filename.ext to see if this is the problem.
|
|
|
|
|
is there a way to convert the path from the standard to the dos path version within vb.net
|
|
|
|
|
you can go here:
http://bytes.com/forum/thread349072.html[^]
or copy/paste
Private Declare Auto Function GetShortPathName Lib "kernel32" (ByVal lpszLongPath As String, ByVal lpszShortPath As System.Text.StringBuilder, ByVal cchBuffer As Integer) As Integer
Private Const MAX_PATH As Integer = 260
Public Function ShortFileName(ByVal LongFileName As String) As String
Dim ShortPath As New System.Text.StringBuilder(MAX_PATH)
Dim BufferSize As Integer = GetShortPathName(LongFileName, ShortPath, ShortPath.Capacity)
Return ShortPath.ToString
End Function
|
|
|
|
|
Perfect. Thanks a million for your help.
|
|
|
|