472,973 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Windows service interaction with WinForms app?

When to use a privileged user thread rather than a windows service?

That's the question raised in a previous post [Make a Windows Service start
a windows program]. It was suggested that if the service needs to interact
with a WinForms app (which is the UI used to adjust the actions taken by,
and the schedule of the service), then a privileged user thread should be
used in the UI - no service required.

But...

"A windows service enables the creation of long-running executable
applications that run in their own Windows session that has the ability to
automatically start when the computer boots and can be manually paused,
stopped or even restarted. Services can run in the security context of an
account that is different from the logged-on user."

This is EXACTLY the behavior required by my application. A single app with
a privileged user thread may avoid the problem of interaction between the
service and the UI, but that's no reason to abandon the design option of a
Service-WinForms app paired together, if that accomplishes the required
functionality.

The problem is the parameters that drive the service are complex. These
parameters are expressed with relational data. The various controls in the
UI are bound to a typed DataSet (persisted to xml) and business logic is
contained in the object that represents the "project" that the service runs.
This is why a separate app is needed to create and configure the projects
that the service runs at various intervals.

The interaction required between the UI and the service is very limited: the
service needs only to instantiate the Project object (with all the methods
and business logic) in the UI app at project runtime. The only other
communication between the UI and the service occurs when the user requests
the "time remaining until next project runtime" from the UI. This
"WaitTime" value is calculated using the value of Timer object maintained by
the service (for each project defined in the UI). The project runtime
intervals are based on system up time, so all the service does is maintain
counters for each project (started and stopped at boot), and launch the
projects when their respective counters reach zero.

The question is:

1) Can the service instantiate an object from the UI app (which is in the
same assembly), and

2) What is the best way to enable the limited communication necessary
between the service and the app?

As far as I know, the service CAN instantiate an object from the UI app, and
it would run in the service's process thread, which is good. But the
interaction between the UI and the service would require interprocess
communication, which is bad. Is this a job for Remoting? Or is there a
better way to pass a simple TimeSpan object from the service to the UI?
Feb 23 '06 #1
2 6810

"deko" <de**@nospam.com> wrote in message
news:ZO********************@comcast.com...
| When to use a privileged user thread rather than a windows service?
|
| That's the question raised in a previous post [Make a Windows Service
start
| a windows program]. It was suggested that if the service needs to
interact
| with a WinForms app (which is the UI used to adjust the actions taken by,
| and the schedule of the service), then a privileged user thread should be
| used in the UI - no service required.
|
| But...
|
| "A windows service enables the creation of long-running executable
| applications that run in their own Windows session that has the ability to
| automatically start when the computer boots and can be manually paused,
| stopped or even restarted. Services can run in the security context of an
| account that is different from the logged-on user."
|
| This is EXACTLY the behavior required by my application. A single app
with
| a privileged user thread may avoid the problem of interaction between the
| service and the UI, but that's no reason to abandon the design option of a
| Service-WinForms app paired together, if that accomplishes the required
| functionality.
|
| The problem is the parameters that drive the service are complex. These
| parameters are expressed with relational data. The various controls in
the
| UI are bound to a typed DataSet (persisted to xml) and business logic is
| contained in the object that represents the "project" that the service
runs.
| This is why a separate app is needed to create and configure the projects
| that the service runs at various intervals.
|
| The interaction required between the UI and the service is very limited:
the
| service needs only to instantiate the Project object (with all the methods
| and business logic) in the UI app at project runtime. The only other
| communication between the UI and the service occurs when the user requests
| the "time remaining until next project runtime" from the UI. This
| "WaitTime" value is calculated using the value of Timer object maintained
by
| the service (for each project defined in the UI). The project runtime
| intervals are based on system up time, so all the service does is maintain
| counters for each project (started and stopped at boot), and launch the
| projects when their respective counters reach zero.
|
| The question is:
|
| 1) Can the service instantiate an object from the UI app (which is in the
| same assembly), and
|
| 2) What is the best way to enable the limited communication necessary
| between the service and the app?
|
| As far as I know, the service CAN instantiate an object from the UI app,
and
| it would run in the service's process thread, which is good. But the
| interaction between the UI and the service would require interprocess
| communication, which is bad. Is this a job for Remoting? Or is there a
| better way to pass a simple TimeSpan object from the service to the UI?
|
|

THE question remains un-answered, do you need to have this application
running when no user is logged on?
If the answer is NO, then you don't need a service you only need a single UI
application, if the answer is yes then you need something that runs across
logon/logoff events, but keep in mind that you can't run a UI application
when no user is logged on.
So, assuming the answer is YES, you'll need a way to communicate and because
both applications running in a different process you need some form of IPC.
There are many forms of IPC available to .NET, one of them is remoting
others are through COM interop, you can even use sockects to communicate or
simply transfer serialized object state through the file system.
The easiest and most native to .NET is remoting and COM+ (enterprise
Services).
So you could have the following set-up:

Windows Service <---- remoting -----> UI application
COM+ service <----- DCOM interop -----> UI Applcation.
Both COM+ and Windows sevices are not tied to the logon session and can both
run as a privileged user.

Notice that in both cases the service cannot control (say start) the UI app,
it's the UI that 'drives' the service (the UI is the client). So it's up to
the UI to pass data (create an instance of a Project object) to the service
where it gets processed. The UI can also request the time remaining until
the next process run.
So, you see it's the UI who drives the process and the Service who executes
the process.

But again, if you don't need the process to run when no user is logged on
forget about all this and use a single WinForms program for all this.

Willy.

Feb 23 '06 #2
> But again, if you don't need the process to run when no user is logged on
forget about all this and use a single WinForms program for all this.


I guess that it THE question...

A separate thread is easy enough in .NET, and running that thread with Admin
privileges, apparently, is easy enough as well. So the only other thing is
when the app starts, which can't be that difficult to control.
Feb 23 '06 #3

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

Similar topics

1
by: Artur Kowalski | last post by:
I have a NotifyIcon in my Windows Service project and I am trying to add a ContextMenu to this NotifyIcon or use some of the mouse events. Everything isn't working. I think so base class of the...
2
by: Ann | last post by:
HI, All Is there a possibility that I could use Crystal Reports in a Windows Service? I am currently working in a project where a particular windows service would import data from excel files,...
1
by: Robert May | last post by:
I have an application that uses the Ax web browser object. When I call the IHTMLElement.click() method on an input button (<input type="submit"> or <input type="button">), the click fires...
3
by: Vitaly Zayko | last post by:
Is it possible to attach a form (C# .NET 2) to windows service and show it in OnStart event? When I tried to do this in general (new, Show()) way it just didn't do anything nor gave me any errors....
17
by: UJ | last post by:
Is there any way for a windows service to start a windows program ? I have a service that will need to restart a windows app if it needs to. TIA - Jeff.
1
by: Steffer [MCP] | last post by:
Hi NG I'm have made a server application (WinForms) but I would very much like to move the tasks that my app runs into a Windows Service. But have you any experience building an communication...
5
by: sonali_reddy123 | last post by:
Hello all, I am trying to develop an application which will run as a windows service. The application should have Normal options available with service like start, stop and pause but along...
2
by: =?Utf-8?B?c3lzdGVtQ29uc3VsdGFudA==?= | last post by:
Can I use EnumchildWindows from a windows service to find the IE windows and Solitaire windows belonging to the logged on user? And if so then I'll need to know what call to use to get the users...
1
by: Susan Harris | last post by:
I have a Windows (NT) service developed in .NET 3.5 (VS2008). I want this service to log messages to a WinForms application that will display it's progress to the user. It has to run under Vista,...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.