Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / July 2005

Tip: Looking for answers? Try searching our database.

User interface from service in .Net

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ken Allen - 07 Jul 2005 17:39 GMT
Can a .Net service be given a user interface? Even if I create it as a
'Windows Service', Visual Studio does not link in the
System.Windows.Forms namespace; and if I do so manually, then the
service hangs inside a WaitOne() inside the invoked delegate for a form
control update -- and the Form.Show() did nothing!

A friend of mine tells me that he was able to do this with VB6, but I
cannot figure out how to do this with C#/.Net -- is it possible?

-Ken
Bennie Haelen - 07 Jul 2005 18:42 GMT
I would not recommend that you display a user interface from a .NET
service. If you really want to, you CAN allow it to interact with the
desktop by checking the "Allow Service to interact with the Desktop"
checkbox, which you can check if you select the "local system account"
in the "Log On" tab of the Local Services MMC applet.

By definition, Services should not be designed to display a graphical
user interface. If you need to display a UI, you can create a seperate
Windows Forms application, which interacts with the service through
remoting or some other IPC mechanism.

- Bennie

> Can a .Net service be given a user interface? Even if I create it as a
> 'Windows Service', Visual Studio does not link in the
[quoted text clipped - 6 lines]
>
> -Ken
Ken Allen - 07 Jul 2005 20:02 GMT
Yes, I know it is not recommended, but there are times when we need
this, even if only for limited periods of time.

Is there no way to enable this in the compilation.build phase? Must it
be enabled only after the service is installed? IN one case we have a
single project that contains multiple services, and we wanted to have a
single form displayed that included information from all of the services.

-ken

> I would not recommend that you display a user interface from a .NET
> service. If you really want to, you CAN allow it to interact with the
[quoted text clipped - 19 lines]
>>
>> -Ken
Norman Yuan - 07 Jul 2005 20:35 GMT
Look into ServiceController Class, which is used for control Wndows
Services.

You can build a standard Win Form App on Service Controller class to
monitor/control the Windows Service(s). Almost all books on Windows Service
have an example of Win Form app, using ServiceController class.

> Yes, I know it is not recommended, but there are times when we need
> this, even if only for limited periods of time.
[quoted text clipped - 29 lines]
> >>
> >> -Ken
Andy - 18 Jul 2005 17:46 GMT
Create an installer class for your service project.

Override the Install method, like so:

    public override void Install(IDictionary stateSaver) {
        base.Install(stateSaver);
               SetInteractWithDesktop();
       }

        private void SetInteractWithDesktop() {
            RegistryKey fm;
            ServiceType type;

            fm = Registry.LocalMachine.OpenSubKey(
@"SYSTEM\CURRENTCONTROLSET\SERVICES\<your_service_name>, true );

            type = ServiceType.InteractiveProcess |
ServiceType.Win32ShareProcess;
            fm.SetValue( "Type", (int)type );

            fm.Close();
        }

That will modify the registry properly to check the Allow interaction
with desktop setting.

HTH.
Andy

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.