Click here to Skip to main content
15,891,033 members
Home / Discussions / C#
   

C#

 
QuestionWindows service cannot able to start Pin
sekannak21-Aug-10 1:18
sekannak21-Aug-10 1:18 
AnswerRe: Windows service cannot able to start Pin
OriginalGriff21-Aug-10 2:11
mveOriginalGriff21-Aug-10 2:11 
AnswerRe: Windows service cannot able to start Pin
PIEBALDconsult21-Aug-10 4:24
mvePIEBALDconsult21-Aug-10 4:24 
QuestionItems in ComboBox Pin
igalep13221-Aug-10 0:56
igalep13221-Aug-10 0:56 
AnswerRe: Items in ComboBox Pin
Dave Kerr21-Aug-10 1:17
mentorDave Kerr21-Aug-10 1:17 
GeneralRe: Items in ComboBox Pin
igalep13221-Aug-10 1:22
igalep13221-Aug-10 1:22 
QuestionPrintPreview WTF? Pin
Dr.Walt Fair, PE20-Aug-10 16:02
professionalDr.Walt Fair, PE20-Aug-10 16:02 
QuestionEvent Handling in Windows Services [modified] Pin
See_Sharp20-Aug-10 7:27
See_Sharp20-Aug-10 7:27 
Hi,

This question is a little generic, but is there a difference in the way Windows Services handle events vs. Windows Forms?

I want to create my own hotkey program to test out a new class I found in one of the articles here(UserActivityHook.cs). When I press 1 key, a combination of keys are sent

In a windows form, I could do something like this (shortened examples):

private void btnStart_Click(object sender, EventArgs e)
{
    hook = new UserActivityHook();
    hook.KeyPress += new KeyPressEventHandler(KeyPressHandler);
}

public void KeyPressHandler(object sender, KeyPressEventArgs e)
{
     string strKeyPressed = e.KeyChar.ToString();

     if(strKeyPressed == 'a')
     {
         SendKeys.Send("B");
         System.Threading.Thread.Sleep(50);             
         SendKeys.Send("N");
     }
}

So for a Windows Service, I have a service up and running, I have confirmed that it starts properly with a few tests.

So if the windows service starts, and I do the same thing:

protected override void OnStart(string[] args)
{
    hook = new UserActivityHook();
    hook.KeyPress += new KeyPressEventHandler(KeyPressHandler);
}

Assuming I have the same event handler, shouldn't this accomplish the same thing? (i.e. the Button click does the same thing as a service starts)

What's happening is that the Windows Forms app sends the hotkeys, but the Windows Service does not, so the event handler didn't run.

I don't know how straight forward this is, but I'm new to windows services Hmmm | :|

Thanks!

modified on Friday, August 20, 2010 1:33 PM

AnswerRe: Event Handling in Windows Services PinPopular
Eddy Vluggen20-Aug-10 7:48
professionalEddy Vluggen20-Aug-10 7:48 
GeneralRe: Event Handling in Windows Services Pin
See_Sharp20-Aug-10 8:14
See_Sharp20-Aug-10 8:14 
GeneralRe: Event Handling in Windows Services Pin
Eddy Vluggen20-Aug-10 8:28
professionalEddy Vluggen20-Aug-10 8:28 
Questionwebpage popping out from iframe [modified] Pin
Hiren solanki20-Aug-10 3:36
Hiren solanki20-Aug-10 3:36 
AnswerRe: webpage popping out from iframe Pin
Łukasz Nowakowski20-Aug-10 3:47
Łukasz Nowakowski20-Aug-10 3:47 
AnswerRe: webpage popping out from iframe Pin
Ennis Ray Lynch, Jr.20-Aug-10 3:49
Ennis Ray Lynch, Jr.20-Aug-10 3:49 
AnswerRe: webpage popping out from iframe Pin
R. Giskard Reventlov20-Aug-10 3:50
R. Giskard Reventlov20-Aug-10 3:50 
AnswerRe: webpage popping out from iframe Pin
Hiren solanki20-Aug-10 4:03
Hiren solanki20-Aug-10 4:03 
GeneralRe: webpage popping out from iframe Pin
Łukasz Nowakowski20-Aug-10 4:12
Łukasz Nowakowski20-Aug-10 4:12 
GeneralRe: webpage popping out from iframe Pin
Ennis Ray Lynch, Jr.20-Aug-10 4:32
Ennis Ray Lynch, Jr.20-Aug-10 4:32 
GeneralRe: webpage popping out from iframe Pin
R. Giskard Reventlov20-Aug-10 4:24
R. Giskard Reventlov20-Aug-10 4:24 
AnswerRe: webpage popping out from iframe Pin
T M Gray20-Aug-10 4:47
T M Gray20-Aug-10 4:47 
GeneralRe: webpage popping out from iframe Pin
Hiren solanki20-Aug-10 16:59
Hiren solanki20-Aug-10 16:59 
GeneralRe: webpage popping out from iframe Pin
Bernhard Hiller22-Aug-10 21:58
Bernhard Hiller22-Aug-10 21:58 
GeneralRe: webpage popping out from iframe Pin
Hiren solanki24-Aug-10 19:31
Hiren solanki24-Aug-10 19:31 
QuestionWCF InvalidCastException - "from in the context ['Default' | 'LoadFrom'] at location" Pin
1eyhk120-Aug-10 0:30
1eyhk120-Aug-10 0:30 
AnswerRe: WCF InvalidCastException - "from in the context ['Default' | 'LoadFrom'] at location" Pin
Eddy Vluggen20-Aug-10 0:56
professionalEddy Vluggen20-Aug-10 0:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.