View previous topic :: View next topic |
Author |
Message |
GRB Advanced Cheater
Reputation: 0
Joined: 17 Nov 2006 Posts: 53
|
Posted: Wed Feb 16, 2011 11:13 am Post subject: C# with Windows.Form Help Needed! |
|
|
Hy all,
Need help to find how to do what i want to do, that is:
After made a GUI in C# with frameworks 4.0, i want the program to be constant watching when a specific process is runing and when its found do (something*). Already searched the net for some related articles, but none of them seemed to helped me. For now im using the timer ability at the start of the program to do what i need to be done, but i know theres a better way to solve this, but i guess it passes me.
Any help at all is really apreciated.
Best Regards GRB
|
|
Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Wed Feb 16, 2011 12:34 pm Post subject: |
|
|
i think a timer is fine as is, tbh.
|
|
Back to top |
|
 |
GRB Advanced Cheater
Reputation: 0
Joined: 17 Nov 2006 Posts: 53
|
Posted: Wed Feb 16, 2011 12:40 pm Post subject: |
|
|
it does the job, but if i want to past text of whats happening to a debug window theres the problem.
Its always saying:
"not found"
"not found"
"not found"
"not found"
"not found"
"not found"
"not found"
every time the timer ticks.
|
|
Back to top |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Wed Feb 16, 2011 3:21 pm Post subject: |
|
|
Post a code snippet. Sounds like you just need to change the code a bit and instead of have it display a message when "not found" have it display when found.
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.> |
|
Back to top |
|
 |
GRB Advanced Cheater
Reputation: 0
Joined: 17 Nov 2006 Posts: 53
|
Posted: Wed Feb 16, 2011 3:34 pm Post subject: |
|
|
AhMunRa wrote: | Post a code snippet. Sounds like you just need to change the code a bit and instead of have it display a message when "not found" have it display when found. |
For that i could take the the listbox1.item.add("not found"); out of there, lol, i really wanted it to say found or not found, other way around this is to use listbox1.clear(); so only 1 line appear, what i really want is not to use the timers for that.
I know theres some way to do it like c++ and even c# console can do it, with the
static void main()
{
while (*****)
{}
}
but i dont know the way to do it with the c# windows.form couse if i put it on the start of the program the gui will never show or it will be on constant loop.
And no the GUI dont have any bottons on it, thats the problem.
Heres the snippet
Code: | public void timer1_Tick(object sender, EventArgs e)
{
if (Process.GetProcesses().Any(prc => prc.ProcessName.Contains("notepad")))
{
listBox1.Items.Clear();
listBox1.Items.Add("Found");
timer2.Start();
timer1.Stop();
}
else
{
listBox1.Items.Clear();
listBox1.Items.Add("NOT Found");
}
System.Threading.Thread.Sleep(50);
} |
Other question, why System.Threading.Thread.Sleep makes a sleep on all computer instead of only sleep my application? its strange that it acts that way.
|
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8585 Location: 127.0.0.1
|
Posted: Wed Feb 16, 2011 3:50 pm Post subject: |
|
|
If you want to just display found or not found use a single label, no reason to use a list box. Don't use Sleep inside timers either, they have a interval for that purpose.
_________________
- Retired. |
|
Back to top |
|
 |
GRB Advanced Cheater
Reputation: 0
Joined: 17 Nov 2006 Posts: 53
|
Posted: Wed Feb 16, 2011 4:18 pm Post subject: |
|
|
wiccann its not to show found or not found, the listbox is were the debug part is, so i can see if the program is reading the right offsets, i dont care for found or not found, so far the program is runing well but i dont want to use timers :/
Here is some pics to you understand it better
P.S- Program wasnt runing, it was waiting on process to start thats why the stats and pics are wrong.
Description: |
|
Filesize: |
21.35 KB |
Viewed: |
10438 Time(s) |

|
Description: |
|
Filesize: |
23.96 KB |
Viewed: |
10438 Time(s) |

|
Description: |
|
Filesize: |
55.92 KB |
Viewed: |
10438 Time(s) |

|
|
|
Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8585 Location: 127.0.0.1
|
Posted: Wed Feb 16, 2011 4:47 pm Post subject: |
|
|
I'm not sure whats wrong with the timer part.. using a thread is more work and more prone to cause errors when closing the application. A timer will automatically cleanup for you.
Basically the only other way to monitor for the process is through a thread. (Without going into any bits of extremes.)
_________________
- Retired. |
|
Back to top |
|
 |
GRB Advanced Cheater
Reputation: 0
Joined: 17 Nov 2006 Posts: 53
|
Posted: Wed Feb 16, 2011 5:35 pm Post subject: |
|
|
Well i guess that i will stay with the timers then
|
|
Back to top |
|
 |
AhMunRa Grandmaster Cheater Supreme
Reputation: 27
Joined: 06 Aug 2010 Posts: 1117
|
Posted: Wed Feb 16, 2011 7:07 pm Post subject: |
|
|
If you are writing a debugger why use a timer anyway. Just have your app throw an exception if you try to click on anything if the app is not found. Return MessageBox.Show("Error!", "The application " + myApp + " was not found!", MB_OK);
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.> |
|
Back to top |
|
 |
Polynomial Grandmaster Cheater
Reputation: 5
Joined: 17 Feb 2008 Posts: 524 Location: Inside the Intel CET shadow stack
|
Posted: Sat Feb 19, 2011 4:20 am Post subject: |
|
|
Just have a global bool on your form class stating whether or not the app is running, then update and do a comparison per tick.
Code: | bool isGameRunning = false;
Process GameProcess = null;
...
void tmrGameCheck_Tick(...) {
Process[] pl = Process.GetProcessesByName("game.exe");
if(pl.Length == 0)
{
if(isGameRunning) {
Debug.WriteLine("Game exited.");
Process = null;
isGameRunning = false;
}
} else {
if(!isGameRunning) {
Debug.WriteLine("Found game process.");
Process = pl[0];
isGameRunning = true;
}
}
} |
That way it only shows the debug message and updates the process object if the state changes from not found to found, or vice versa.
_________________
It's not fun unless every exploit mitigation is enabled.
Please do not reply to my posts with LLM-generated slop; I consider it to be an insult to my time. |
|
Back to top |
|
 |
|