473,394 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Calling method when process starts

17
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:
Expand|Select|Wrap|Line Numbers
  1. Process[] cs = System.Diagnostics.Process.GetProcessesByName("hl");
  2.             foreach (Process p in cs)
  3.             {
  4.                 csRem.Set(csRemH, csRemM, csRemS);
  5.                 csTimer.Start();
  6.             }
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.EnableRaisingEvents = 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.
Jul 23 '09 #1
3 2365
GaryTexmo
1,501 Expert 1GB
I don't personally know how to write a process monitor tool, but I did a google search and there should be some support out there if nobody here can help you.

Actually, one link I found, which sounds like it might be right up your alley is:
http://www.mycsharpcorner.com/Post.aspx?postID=24

I will say though, be careful with these tools as STEAM does do it's best to monitor background processes which interact with its programs in an attempt to detect cheating, though as long as you're not hooking into the executables you should be fine. The code in that link just monitors the currently running processes so that shouldn't be anything "bad" so far as STEAM is concerned.

At this point I'd say you could probably save yourself a lot of time and effort with an alarm or two and some willpower, and that you'll likely actually spend more time on the computer developing this tool than you would just playing CS anyways, but my inner-geek totally understands where you're coming from.

Best of luck!
Jul 23 '09 #2
Saser
17
Thanks! I'll see if this code helps me :)

I started creating this program for two main reasons:
1. To have control over my time at the computer.
2. The programmming challenge.

You're right, I've been spending a little too much time at my computer since I started this project, but look at it from this point: instead of playing a game, I've been creative, and developed something that helps me :)

I'm soon going to "release" this project to my friends, if they want to, but to be able to release it to the people that doesn't know C# or any programming at all I've got to provide some kind of Settings-dialog. So in the end I think my little app will help, not only me, but other people as well. :)

Thanks,
Saser
Jul 23 '09 #3
Did you try registering to the Process.Exited event?

http://msdn.microsoft.com/en-us/libr...ss.exited.aspx
Jul 25 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: pieter.breed | last post by:
Hi All, Is it possible to export a c# method into a dll in such a way that your "normal" C application can then call this method? To be clear: I am not asking how to use "DllImport" or...
24
by: Jazper | last post by:
hi i have this problem. i made a class deverted by CRootItem with implementation of IDisposable-Interface. i made a test-funktion to test my Dispose-Method.... but when set a breakpoint in my...
7
by: JJ | last post by:
Hi, I call a class in my windows service app and in that class I access a method that returns an OleDbReader. Now It does have records in the reader when I step through the method but when I...
1
by: Nick Bishop | last post by:
I have a problem where I call a method in a C++ class with a pointer which is a static member in that class. When I use a debugger, I see the pointer having a certain value, but when I step into...
3
by: Martin Knopp | last post by:
Anybody here can shed some light on this issue? Is it at all possible to call out-of-proc COM objects from ASP.NET? If yes, what configuration settings are required? I played around many...
5
by: Nick Flandry | last post by:
I'm running into an Invalid Cast Exception on an ASP.NET application that runs fine in my development environment (Win2K server running IIS 5) and a test environment (also Win2K server running IIS...
7
by: Stu | last post by:
Hi, I have a web service which returns a record set and works well integrated with an asp dot net page. However if I decided to develop a unix app will i be able to read the dataset as it is...
7
by: christian13467 | last post by:
Hi, I'm using ASP.Net 2.0 with IIS 6.0 on windows server 2003 sp1. Calling a commandline program or a cmd file using Process.Start inside a webservice method. The call to Process.Start returns...
9
by: Pubs | last post by:
Hi all, I want to call a function with some intial parameters with in a thread. At the end of the function execution it should return a value to the caller. Caller is outside the thread. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.