Threads / Timers Troubles While Creating System Service
Apr 5, 2012
I thought that creating a simple system service under VB .NET would be a piece of cake. Boy, was I wrong. First, I find general postings through Google that say you should use the Windows.Forms.Timer. Then, I found conflicting information that says you have to derive the timer from a timer class through code to make it work. Then, people are reporting all sorts of trouble using the various types of threads available. I can't debug threads using the VS 2010 Just-in-Time debugger for obvious reasons (although, I don't know if there is an alternate method to doing this).My project is an application launcher (similar to cron) that will fire off periodically within a certain amount of seconds. I am trying to use the Process.Start() method. I have a Beep() function as the first instruction, and the Process.Start, along with a Process.WaitForExit method to make it block as the last instruction. I had my code doing this through timers, but now I am starting to use threads. No difference in execution. The over-ridden OnStart method does kick off (as I am certain through debugging), but nothing ever happens when starting the service in production, as if it were ignoring all my code. Putting loops and logic in the OnStart method yields a process that won't start. I know it is a threading issue, but I also know it must be mandatory to use threads. I am now dumbfounded as to how to make this work. I am curious to know the solution.
In addition to the service class, I have a ServiceInstaller and ProcessInstaller implemented that I copied verbatim from MSDN.Here is some of the code I am trying to work with. Note that this simply reflects the current state of my code in trying to implement the logic within a thread instead of a timer (which to me would be optimal):[code]
View 2 Replies
ADVERTISEMENT
Apr 4, 2012
Here is the stack trace:
2012-03-16 19:15:09Z E System.NullReferenceException: Object reference not set to an instance of an object.
at System.Timers.Timer.set_Enabled(Boolean value)
at System.Timers.Timer.Stop()
Here's the code:
Timer declared as private member variable.
Private _myTimer As System.Timers.Timer
Initialize timer method.
[code]....
The timer has to have a value or else the Timer.Stop() call would be throwing the exception. This is a sporadic error and I'm just trying to see if anyone has experienced this before or if anyone has any ideas of what could be causing it. It is occuring in a WinForms application in the event handler for the Elapsed event of the Timer, but it is only occuring sporadically on the users computer. I haven't been able to reproduce the error myself.
View 2 Replies
Jun 15, 2009
I'm wondering what exactly is the difference System.Timers.Timer and System.Windows.Forms.Timer???
View 4 Replies
Jun 27, 2012
I'm looking at how to pause a System.Timers.Timer and I cannot figure out the proper way to pause it without resetting the timer.
View 4 Replies
Apr 18, 2011
I have a problem with the Timer class in that there is a chance that a timer would fire right before you call Dispose() since you will probably call Dispose() from some other thread. You may have something like:
Public Sub TimerTick() Handles itsTimer.Elapsed
Do Something
End Sub
And then from somewhere else in the code, when your app is done, you call
itsTimer.Dispose()
The only way I can think of doing this is:
Public Sub SomeMethod()
SyncLock(itsTimer.SynchronizingObject)
itsTimer.Dispose()[code]...
This is not a great thing to do esp. since I am holding a lock on an object I am disposing. I can create my own lock and syncLock on that but is there a simple way?
View 2 Replies
Oct 18, 2009
is it possible to specify a System.Timers.Timer with 0.1ms interval?
View 14 Replies
Mar 8, 2011
I'm creating a multi-threaded application (although it is not at the moment) which will be connecting to a large number of sockets. I've noticed when a connection cannot be made the connect timeout is rather large, so I am trying to make my own. Here is what I have come up with...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
CreateSockets(2)
AssignSockets(0, "192.168.31.2", 80, False, False) 'shouldn't connect
AssignSockets(1, "192.168.1.1", 80, False, False) 'should connect
[code]....
Looking at the timeoutOccured() sub, you can see I'm unsure of how to specify which index to set. Efficiency is important since this will be housing a lot of connections at once. Something else that just came to mind, would .theTimer.Stop reset the tick value on the timer?
View 4 Replies
Mar 15, 2010
I got this warning that I don't know what it means.Warning1 The service System.ComponentModel.Design.IInheritanceService already exists in the service container.Parameter name: serviceType00
View 2 Replies
Feb 2, 2011
There is a problem with standard System.Timers.Timer behaviour. The timer raise Elapsed event with some interval. But when time of execution inside Elapsed event handler exceed timer interval then thread pool begin queuing event handling. This is a problem in my case. This is because with my Elapsed event handler I fetch some data from database and doing something with it and finally save results back to database. But data handling should be provided only once. So, is there a way to prevent from queuing elapse events for System.Timers.Timer.
As illustration for this issue you can consider next test program:
[code]...
2) Second way is about SynchronizingObject, but it is a valuable only for Windows form application or required additional development of code for implementing object that would be implements ISynchronizeInvoke interface. More about this way you can find here
View 4 Replies
Sep 28, 2010
To get pass the cross referencing error when running a thread, I use this code
[Code]...
But the AddressOf doesn't accept parameters... So how do I get pass that? Or is there another way to use delegate?
View 6 Replies
Mar 24, 2011
I am using timers in a windows service and facing problem that anytime some exception happens ( say i unplug LAN wire from my computer ) service stops running, What i am expecting is that service should keep on running as i am catching generic exception which should catch the exception on one tick event and again work (next tick)when i plug in LAN wire (i am plugging/un plugging ) LAN wire as this service is reading database from LAN so i want to replicate a failover scneario)
View 3 Replies
Apr 29, 2010
I have ran into a situation where it would be a lot faster to create a thread by the users demand. Basically, what I have is some kind of downloading program which grabs URLs from the clipboard into a DataGridView. Now when multiple URL's have been added, it becomes really inefficient since only one URL is being processed at a time.Now what I wanted to do is, create a thread for each URL. The parameter for each thread are the URLs which are stored as strings inside the DataGridView rows.[code]
View 3 Replies
Jun 1, 2011
How do I make my program create new threads from a set amount? For example if someone typed "60" in a textbox and they pressed "Start", it would create 60 threads that would do the same function.
View 5 Replies
Nov 12, 2009
I just want to create an service which will on start read my XML file .It gets the number of parameters connected to PC. I just want to know that is it possible to create the timers at run time in my service and the timers should start at the same time but will having different time span to exicute means one timer will start after every one minute while another after 2 or 3 or whatever i set.
View 1 Replies
Dec 17, 2007
In a windows forms application I am attempting to read a file from a share into a filestream.I then start impersonating and write the stream to another share that only my impersonation account has access to.This works fine for small files. But if I attempt this on a 90 meg file I recieve a "Insufficient system resources exist to complete the requested service" error on the following line:
System.IO.File.WriteAllBytes(myLocation,MyByteArray)
Full Example:
Dim ImageData As Byte() = Nothing
Dim fsAttachment As IO.FileStream = Nothing[code].....
View 10 Replies
Jan 15, 2009
I need an accurate timer to interface a Windows application to a piece of lab equipment.I used System.Timers.Timer() to create a timer that ticks every 10 msec, but this clock runs slow. For example 1000 ticks with an interval of 10 msec should take 10 wall-clock seconds, but it actually takes more like 20 wall-clock sec (on my PC). I am guessing this is because System.Timers.Timer() is an interval timer that is reset every time it elapses. Since it will always take some time between when the timer elapses and when it is reset (to another 10msec) the clock will run slow. This probably fine if the interval is large (seconds or minutes) but unacceptable for very short intervals.Is there a function on Windows that will trigger a procedure every time the system clock crosses a 10 msec (or whatever) boundary?
UPDATE: System.Timers.Timer() is extremely inaccurate for small intervals.I wrote a simple program that counted 10 seconds several ways:
Interval=1, Count=10000, Run time = 160 sec, msec per interval=16
Interval=10, Count=1000, Run time = 16 sec, msec per interval=15
Interval=100, Count=100, Run time = 11 sec, msec per interval=110
Interval=1000, Count=10, Run time = 10 sec, msec per interval=1000
It seems like System.Timers.Timer() cannot tick faster that about 15 msec, regardless of the interval setting.Note that none of these tests seemed to use any measurable CPU time, so the limit is not the CPU, just a .net limitation (bug?)For now I think I can live with an inaccurate timer that triggers a routine every 15 msec or so and the routine gets an accurate system time. Kinda strange, but...I also found a shareware product ZylTimer.NET that claims to be a much more accurate .net timer (resolution of 1-2 msec). This may be what I need. If there is one product there are likely others.
View 5 Replies
Mar 19, 2012
When I run my app at first its keeps time accurately for the first minute or so there after it starts loosing seconds, and by the end of the day its minutes behind.I've created a class called ServerTimeTimer that has a timers.timer object that elapses every second and adds a second to a dateTime variable, and a property to retrieve the date time.[code]
View 5 Replies
Jul 12, 2010
I am new to .net, I am just taking a shot in the dark through this whole thing. I have an Addresses table with a StateID and CountryID field. They refer to the States and Countries table. I am using LINQ to SQL and Visual Studio 2010.
[Code]...
View 1 Replies
Oct 31, 2010
when I got home to try out the method in the above post in my real application things did not work out.The big difference is that my main form is a MDI. When I open my edit form, it's mdiparent is set to the main form. When I click 'edit' and then disable "me" the entire application goes modal.I was expecting only the MDI child to go disabled, not the whole application..Basically, I want only the MDI child window that opens it's "edit" dialog to go disabled..
View 1 Replies
Apr 15, 2011
I am using the following code to parse a XML file of mine:
Dim xml As String = "<?xml version=""1.0"" encoding=""Windows-1252""?>" & _
"<theref:theref-msg xmlns:csr=""http://www.xxxxx.com/Schema/csr""
xmlns:theref=""http://www.xxxxx.com/Schema/theref"">" & _
[code].....
View 2 Replies
May 26, 2010
im making a game for my assignment of snake. Vb10 Im coding 90% by teaching myself. Was just wondering if anyone has any idea how to help me. Im stuck with the array for making new pictureboxes and moving them to extend the snake here i some of the code.
Private
SnakeHead.Left = SnakeHead.Left + xDifference
SnakeHead.Top = SnakeHead.Top + yDifference
If SnakeBody(1).Left <> SnakeHead.Left And
SnakeBody(1).Top <> SnakeHead.Top Then
[Code]...
View 13 Replies
Oct 19, 2011
I just had a new, last-minute idea on to take on a task, so I am running to StackExchange for quick help.
What I want to do is execute a series of methods right in a row, each in their own threads. I want the application to wait until all of these threads are completed, after which the program will resume. It also has to use managed threading (thread pool).
What quick examples could you provide to help me along the way? If it's too complex, what things should I know about so that I can Google it on my own?
View 1 Replies
Dec 30, 2009
I have a main thread which is designed to be a batch processor - it spawns a series of 'child' threads from a loop (which can vary in terms of the no of items) - see below
[Code]...
However, each of the 'child' threads could take anywhere from milliseconds to about a minute to process - depending on the complexity of each calculation. There may also be a large number of child threads - e.g 100s. Creating large numbers of child threads is not efficient. I therefore want some way to effectively queue each child thread (and cancel if the process is taking too long to complete). Autoevents seems like one way of doing this, but the only examples I can find seem to assume there are two different processes on seperate threads, not one process being repeated.
View 4 Replies
Sep 19, 2011
I'm trying to start a process from a service (kind of an on-demand process) using the code bellow:
elproceso = New Process()
Dim informacion_inicio As New ProcessStartInfo(dataReader(2))
elproceso.StartInfo = informacion_inicio
elproceso.Start()
View 4 Replies
May 13, 2010
I want to create some sort of method of creating a web service that will run automatically and run DB queries and some API calls which will then store data that I can use/call without taking the processing or time penalty of doing it every time a user access my web service. how to implement something like this
Using vb.net and ASP.net
View 2 Replies
Jun 23, 2010
My first post as an absolute last resort. In 8 years of programming, I have never posted to a programming forum and have always been able to wiggle my way out of any diffficult project...Until this project.Every step of this project is new for me (Windows service, ini file, IIS, FTP, cmd line params, comparing file specs programmatically, using a timer, and even VB.NET is still confusing to me after several years in VB6 ). Dreading posting b/c I have so many questions. I have finished the internet, been to the end and back. Found endless suggestions of code and links and forums and only gotten more lost in the process.
I am trying to create a VB.NET app, that most likely will need to be a service, for our external clients' PCs. These PCs are not connected to our network. This app will be invisible to the user and will need to perform several tasks including:
[Code]...
View 1 Replies
Nov 4, 2010
I've spent alot of time digging thru the forums to research this problem, and to get the right code. I'm wondering now if this is a system configuration problem, or something else with my code.
Firstly, i'll tell you that i've already put the service account on my machine local security policy that says 'allow to act with/as operating system'.
Running this code from an application, it works just fine:
[Code]...
View 1 Replies
Oct 23, 2008
how to write a web to connect SQL 2005 database by having the SQL sa password in the config in encrypted formatted.
View 1 Replies
Dec 2, 2011
What I am looking to do is write a VB.NET program, as a service that reports anything on client1 that I want (say the fact it is online) to a database on the internet, so I can look on management1 and see the online status of the machine (assuming management1 has a connection to the online database).
What is being reported doesn't matter, what I am looking at is a starting point to create a system like that. I have googled obviously and come up with nothing, I'd just like a "starting point" or some documentation to look at for creating something like this. The service doesn't look too difficult but the periodic reporting of online status or ANYTHING to any kind of database is not something I am sure how to deal with.
I already have setup a VBS that reports information to an ASP script that then places it in a database but I don't know how I would create say a "keep alive" connection for a vb.net service.
View 1 Replies
May 30, 2010
I'm connecting to a Web Service that returns a system.xml.xmlnode. How can I convert that to a datatable?
View 3 Replies