473,586 Members | 2,817 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Windows Service or Scheduled Task

I have a vb.net winforms application that I want to run every time the
server starts up (it will be running on a server, and it is okay to have a
user interface). I have had a ton of trouble converting the whole project to
a windows service (tons of apartment threading issues), so I want to run it
as a scheduled task or as a simpler windows service. What I mean by a
simpler windows service is to create a simple application that just calls
the application with the correct parameters. But I need to write code on the
OnStop event in the windows service to properly shut down the application.
I saw this code on the web which can just find the name of an application
and shut it down, but I don't know if this leaves a mess behind. I have
seen a lot of problems in the posts with using Windows Scheduler. Any ideas
on the best method? Should I run KillProcess on the OnStop in the service?

Public Shared Function KillProcess(ByV al procName As String, ByVal Gentle As
Boolean)

Try

' Quickly closes any program. Can do a loop and show the names of
the processes

' if you want to figure out a process name. Just unremark the msgbox
and remark

' the if proc.processnam e.toupper block to see the names.

Dim proc As Process

Dim processes() As Process = Process.GetProc esses()

For Each proc In processes

'MsgBox(proc.Pr ocessName)

If proc.ProcessNam e.ToUpper = procName.ToUppe r Then

If Gentle Then

proc.CloseMainW indow()

' Start over if still open.

KillProcess(pro cName, Gentle)

Else

proc.Kill()

' Start over if still open.

KillProcess(pro cName, Gentle)

End If

End If

Next

Catch ex As Exception

MessageBox.Show (ex.Message, "Error", MessageBoxButto ns.OK,
MessageBoxIcon. Stop)

End Try

End Function

Derek


Dec 9 '06 #1
0 1001

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
4065
by: Codemonkey | last post by:
Hi, I am writing an App in .Net that involves some scheduling of tasks. I was wondering if anybody has come accross any components or examples of how to implement a schedule manager like the one in the Task Scheduler for Windows? Basically I'm after something that'll allow me to specify a "recurring" or "once off" schedule with advanced...
3
2165
by: timb | last post by:
Hi, I have created a windows service which is responsible for running certain tasks when they are scheduled to run. The service monitors a sql table and runs a task when the task scheduled time is overdue. This service is installed at several sites and on 4 out of 5 sites runs the tasks correctly on schedule. However on some other sites the...
14
846
by: Codemonkey | last post by:
Hi, I am writing an App in .Net that involves some scheduling of tasks. I was wondering if anybody has come accross any components or examples of how to implement a schedule manager like the one in the Task Scheduler for Windows? Basically I'm after something that'll allow me to specify a "recurring" or "once off" schedule with advanced...
3
2140
by: nkunapa | last post by:
Hi: I am looking for any ideas/comments/suggestions on how a Windows Service kind of functionality can be acheived from a web application which which will run under IIS or for that matter any application server say Tomcat. I have a Windows service which should run every half hour and call four different methods in a Web Service in serial...
7
2288
by: ss | last post by:
I created a Windows Service to update a database. I have an installer as well and I am running it by choosing to "Start" from "services". I would like to have this service execute at 4 in the morning everyday. I have seen code to start it on intervals but I need to run this at a specific time. Any help in this regard is greatly appreciated....
0
7911
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7954
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8215
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3836
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1179
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.