Hi all bytes out there.
I have a few little problems in my program.
The program is supposed to help me to not spend too much time of my day at the computer ;)
I play a game called Counter-Strike (CS) a lot, but I'm limited to 2 ½ hours a day, and a total of 4 hours a day. I have one button in my program which starts CS, and one button that "kills" CS. The Start-button starts a timer, and the Stop-button stops it. But I want to start the timer even if the game is started from somewhere else, like from the program Steam which you play CS from. In Steam you can double-click at a game, and the game starts. How do I call the method for starting the timer when the process for the game (hl.exe) starts?
I also want to stop the timer when the game quits.
Regards,
Saser
EDIT: Solved the first problem, but I think it's not a very good solution, have a look for yourself:
This is called everytime the timer totTimer ticks (interval 1000 ms). csRem is a time, csRemH, csRemM and csRemS is ints that tell how much time I have left in CS, csTimer is the timer for my CS-time.
EDIT2: Tried to set csProcess.Enabl eRaisingEvents = true, but when I start CS from the button in my program, the timer doesn't start. Weird.
EDIT2.1: Oh sorry, it did start the timer, but it wont call the method for stopping the timer when CS quits.
I have a few little problems in my program.
The program is supposed to help me to not spend too much time of my day at the computer ;)
I play a game called Counter-Strike (CS) a lot, but I'm limited to 2 ½ hours a day, and a total of 4 hours a day. I have one button in my program which starts CS, and one button that "kills" CS. The Start-button starts a timer, and the Stop-button stops it. But I want to start the timer even if the game is started from somewhere else, like from the program Steam which you play CS from. In Steam you can double-click at a game, and the game starts. How do I call the method for starting the timer when the process for the game (hl.exe) starts?
I also want to stop the timer when the game quits.
Regards,
Saser
EDIT: Solved the first problem, but I think it's not a very good solution, have a look for yourself:
Code:
Process[] cs = System.Diagnostics.Process.GetProcessesByName("hl");
foreach (Process p in cs)
{
csRem.Set(csRemH, csRemM, csRemS);
csTimer.Start();
}
EDIT2: Tried to set csProcess.Enabl eRaisingEvents = true, but when I start CS from the button in my program, the timer doesn't start. Weird.
EDIT2.1: Oh sorry, it did start the timer, but it wont call the method for stopping the timer when CS quits.
Comment