473,320 Members | 1,580 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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()
{
InitializeComponent();
}

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

for (...)
{
...
...
ThreadStart ts = new ThreadStart(SomeClass.SomeMethod);
Thread wrkThread = new Thread(ts);
whatever.CurrentThread = wrkThread;
wrkThread.SetApartmentState(ApartmentState.STA);
wrkThread.Start();
}
return;

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

Jan 5 '07 #1
3 4576
>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.ServiceProcess.ServiceBase 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()
{
InitializeComponent();
}

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

for (...)
{
...
...
ThreadStart ts = new ThreadStart(SomeClass.SomeMethod);
Thread wrkThread = new Thread(ts);
whatever.CurrentThread = wrkThread;
wrkThread.SetApartmentState(ApartmentState.STA);
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 ManualResetEvents to manage the thread
shutdown.

DeveloperX wrote:
No is the short answer, the main class inherits from
System.ServiceProcess.ServiceBase 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()
{
InitializeComponent();
}

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

for (...)
{
...
...
ThreadStart ts = new ThreadStart(SomeClass.SomeMethod);
Thread wrkThread = new Thread(ts);
whatever.CurrentThread = wrkThread;
wrkThread.SetApartmentState(ApartmentState.STA);
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
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...
12
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...
15
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...
7
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...
3
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...
10
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...
5
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()...
28
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). ...
1
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.