473,625 Members | 3,085 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Application.Run and Windows Service (Multithreaded)

I have a multithreaded application that I now want to convert into a Windows
Service. Does application.run work in a windows service? Are there things
to take into consideration when creating a multithreaded windows service as
opposed to a multithreaded windows forms application?
E.G.

namespace whatever
{
public partial class Form1 : Form
{
....
public Form1()
{
InitializeCompo nent();
}

private void Form1_Load(obje ct sender, EventArgs e)
{
SomeArray = new SomeClass[# - #];

for (...)
{
...
...
ThreadStart ts = new ThreadStart(Som eClass.SomeMeth od);
Thread wrkThread = new Thread(ts);
whatever.Curren tThread = wrkThread;
wrkThread.SetAp artmentState(Ap artmentState.ST A);
wrkThread.Start ();
}
return;

}
}
public class SomeClass
{
// ...
// ...
private void SomeMethod()
{
....
....
Application.Run ();
}
}
}

Jan 5 '07 #1
3 4596
>I have a multithreaded application that I now want to convert into a Windows
>Service. Does application.run work in a windows service?
Why are you considering calling it? Windows services don't have UI so
there's probably no point in doing so.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jan 5 '07 #2
No is the short answer, the main class inherits from
System.ServiceP rocess.ServiceB ase and ServiceBase has a Run method.
The easiest way to see how it works is to create a service from the
Windows Service template in VS, if you don't have that, I can knock you
up an empty service that shows the basics.

Jake K wrote:
I have a multithreaded application that I now want to convert into a Windows
Service. Does application.run work in a windows service? Are there things
to take into consideration when creating a multithreaded windows service as
opposed to a multithreaded windows forms application?
E.G.

namespace whatever
{
public partial class Form1 : Form
{
...
public Form1()
{
InitializeCompo nent();
}

private void Form1_Load(obje ct sender, EventArgs e)
{
SomeArray = new SomeClass[# - #];

for (...)
{
...
...
ThreadStart ts = new ThreadStart(Som eClass.SomeMeth od);
Thread wrkThread = new Thread(ts);
whatever.Curren tThread = wrkThread;
wrkThread.SetAp artmentState(Ap artmentState.ST A);
wrkThread.Start ();
}
return;

}
}
public class SomeClass
{
// ...
// ...
private void SomeMethod()
{
...
...
Application.Run ();
}
}
}
Jan 5 '07 #3
Oh I should add, threading is simpler in a service as there's no GUI so
no BeginInvoke calls, however you do need to manage the process of the
servicebase receiving a Stop message. I've got a service or two here
which are multithreaded, I use ManualResetEven ts to manage the thread
shutdown.

DeveloperX wrote:
No is the short answer, the main class inherits from
System.ServiceP rocess.ServiceB ase and ServiceBase has a Run method.
The easiest way to see how it works is to create a service from the
Windows Service template in VS, if you don't have that, I can knock you
up an empty service that shows the basics.

Jake K wrote:
I have a multithreaded application that I now want to convert into a Windows
Service. Does application.run work in a windows service? Are there things
to take into consideration when creating a multithreaded windows service as
opposed to a multithreaded windows forms application?
E.G.

namespace whatever
{
public partial class Form1 : Form
{
...
public Form1()
{
InitializeCompo nent();
}

private void Form1_Load(obje ct sender, EventArgs e)
{
SomeArray = new SomeClass[# - #];

for (...)
{
...
...
ThreadStart ts = new ThreadStart(Som eClass.SomeMeth od);
Thread wrkThread = new Thread(ts);
whatever.Curren tThread = wrkThread;
wrkThread.SetAp artmentState(Ap artmentState.ST A);
wrkThread.Start ();
}
return;

}
}
public class SomeClass
{
// ...
// ...
private void SomeMethod()
{
...
...
Application.Run ();
}
}
}
Jan 5 '07 #4

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

Similar topics

5
4655
by: VinnieT | last post by:
I have a load balanced system that consists of 3 production servers. There are about 20 different applications that are used on these boxes. One of my applications in particular is used more than the others. Since updating 2 applications, I have had problems on the event log of the servers, following stopping of the aspnet_ws.exe process. Something is causing the following error in the windows application event log: The description for...
12
4878
by: Chakkaradeep | last post by:
Hi all, I created a Minimal Windows Service Program in Visual Studio.NET VC# using the Wizard...i just added the MessageBox Display in OnStart() function and my service is installed properly...but when i started the Service it display that "Local Service started and stopped , Serivces should have Log Support and Alerts Isssued".. what is this error??...am running Windows XP Home Edition,
15
2132
by: Chakkaradeep | last post by:
Hi all, i have written a Service,now i want to execute another application (for eg;calc.exe) in the service....how will i perform it??... i tried using this.... /**************Executing a Process code starts here**************/ System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents=false;
7
2265
by: Pavils Jurjans | last post by:
Hello, I wanted to get some light in the subject. As I develop ASP.NET applications, it's necessary to understand how exactly the server- communication happens. It seems like initially application is "sleeping", and it is not loaded in the memory. Then, after very first request to the app, it is compiled (aspx files), loaded into memory, and executed. Then, a separate thread is issued to serve my page request, and it takes care for me...
3
2142
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 mode. The methods will have to wait for the previous one to finish and if the previous one is a really...
10
4971
by: John | last post by:
I currently have a Windows Service that runs Transactions that are very Processor/Memory Intensive. I have a requirement to deploy multiple instances of the Web service on the Same server. Each Instance needs to run in its own process. My current approach to this is to put all the logic into a separate "Worker" assembly and install it into the GAC. I'm then going to create Multiple Windows Services (i.e. MyService1, MyService2 etc..)...
5
2609
by: DarkPearl | last post by:
Bonjour à tous, apres avoir créer un service windows avec py2exe, j'ai ce probleme quand je lance le service : voici ce que je trouve dans le journal d'evenement : The instance's SvcRun() method failed <Error getting traceback - traceback.print_tb() failed <class 'pywintypes.com_error'>: (-2147221020, 'Syntaxe incorrecte',
28
7361
by: | last post by:
I have a multi threaded windows form application that runs great after calling Application.Run(). Application.Run is required for a COM component I a using in the app (required for message loop). I have created a windows service from VStudio 2005 template. What is the windows service replacement for Application.Run()?
1
1705
by: hadimani | last post by:
how to check the robustness of an event driven multithreaded application that runs as windows service without any user interface?
0
8259
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8696
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8358
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8502
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7188
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5571
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4090
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1805
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1504
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.