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 / Languages / C# / November 2006

Tip: Looking for answers? Try searching our database.

Services and Application.Run

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Simon Tamman - 19 Nov 2006 00:33 GMT
Will Application.Run() work within a service? (e.g. will the message pump be
operational)
My service works as an exe but not a service, i'm wondering it's it's due to
that.

Kind Regards

Simon
Cor Ligthert [MVP] - 19 Nov 2006 05:00 GMT
Simon,

You are sure that your service has not any user interface at all?

Cor

> Will Application.Run() work within a service? (e.g. will the message pump
> be
[quoted text clipped - 6 lines]
>
> Simon
Simon Tamman - 19 Nov 2006 14:35 GMT
There is no UI, it's trying to pick up ALL the keydown events from the
WinAPI via: SetWindowsHookEx in user32.dll.
The application's aim is to just disable the keyboard.
For the API call to work it needs an Application.Run() somewhere to get the
windows message pump running.
In my console app I spawn a thread to hook up the events and then call
Application.Run() that works fine. However, now i've converted it into a
service it no longer works.

Wah.

Any ideas?

> Simon,
>
[quoted text clipped - 12 lines]
> >
> > Simon
Willy Denoyette [MVP] - 19 Nov 2006 15:12 GMT
> There is no UI, it's trying to pick up ALL the keydown events from the
> WinAPI via: SetWindowsHookEx in user32.dll.
[quoted text clipped - 27 lines]
>> >
>> > Simon
Willy Denoyette [MVP] - 19 Nov 2006 15:30 GMT
> There is no UI, it's trying to pick up ALL the keydown events from the
> WinAPI via: SetWindowsHookEx in user32.dll.
[quoted text clipped - 8 lines]
>
> Any ideas?

You are trying to read/process "windows messages", so you effectively have a User Interface.
This is not possible because the service runs in the context of a non-interactive
desktop/winsta,. For a service to run in the same context as an interactive user, you'll
have to set the "interact with desktop" which requires the service to run in the
"localsystem" account. Note that you should only enable this for debugging purposes, and
it's something which won't work on Vista anyway.

Willy.
Simon Tamman - 20 Nov 2006 01:04 GMT
Thank you very much for your help!
Sure enough setting that checkbox to true allows it to run and receive the
events correctly.

Why should this method of operation be only advisable for debugging, is
there a problem with using it in production?

Kind Regards

Simon

> > There is no UI, it's trying to pick up ALL the keydown events from the
> > WinAPI via: SetWindowsHookEx in user32.dll.
[quoted text clipped - 17 lines]
>
> Willy.

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.