By hooking into TerminateProcess or NtTerminateProcess you can achieve what you're looking for. I seriously doubt though that having a .NET C# function as a hook function is a.) advisable and/or b.) a feasable thing.
If you want to invest some time/work to get going in C++ this CP articel might come in handy: Easy way to set up global API hooks[^]
This question comes up regularly in one form or another in this forum. While I appreciate that you have a legitimate reason for wanting to do this, you have to appreciate that we are averse to posting information that will let any old script kiddy create a malware application that can't be terminated. Sorry.
I'm not a stalker, I just know things. Oh by the way, you're out of milk.
hey guys..i have a chart control and a datagridview on my form..i want to show the values in a graphic which i have in datagridview..Here is how it looks..i have some questions about it.
1) how i can arrange YAxis increase rate as 1..it increases by 5.
2) how i can move the black lines on backround of my chart area?
3) there are two series(Series 1 and Sayilar) there..i couldnt find any example that i can use Series1..i mean the chart control already has..that is why i created new one(Sayilar)..my question is how i can use Series2 or how i can remove it..here is the codes i created and added it to my chart control
4) how i can add some texts of Chart control Axis to inform the user which columns means what
I've written a small monitoring app in c# that notifies the user of specific events on the pc. The wish I would like to have is for the one and only control (Label) to be static on top of the task bar. Currently I've just got a timer running that places it as the top most window, I'd like to eliminate the timer and just have it pinned sort of to the taskbar (not in the notify area). Any direction you may provide would be helpful.
When i wrote a "Source" property as full path "C:\aaa\aaa\aaa\aa\fileName" i do hear the sound, but when i'm trying to set the path using the resources, it doesn't work (no sound), i've marked build actions of the media file as "resources". and in source i wrote /namespace;component/Resources/filename
I had to write a function that was essentially "given some random object at RUNTIME as 'object o' and some random property as 'string propertyName' at RUNTIME, return property o.[propertyName] as an object."
First thought was naturally reflection.
for (i = 0; i < 1000000; i++)
// get property 1 million times through reflection
that took 4.4 seconds on my machine. I unwound the loop a bit and got it down to 2.1 seconds.
Then I switched it over to LINQ expression trees and got it down to 93 MILLSECONDS. 4.4 seconds down to 93 MILLSECONDS...
Now, LINQ expression trees are very poorly documented in MSDN and a search on google and CodeProject turns up very little. It did take me about 5 hours to figure them out (on a super basic level).
But why aren't they used more often? 4.4 seconds vs. 93 millseconds sounds like a big deal to me .
May be, but that won't be the primary reason. Primary reason could be that expression trees can be compiled which gets translated into IL opcodes. This is way faster than reflection looking for a method and invoking it. If the method signature is known at compile time, converting reflection's MethodInfo to a strongly typed delegate will also improve the performance.
I don't have production code that goes for (int i = 0; i < 1000000; i++) . Its called benchmarking code .
"version 1" didn't cache anything and it took 4.4 seconds to run 1 million times
"version 2" cached the PropertyInfo object and it went down to 2.1 seconds to run 1 million times. I can't cache the propertyInfo.GetValue() call, that would a) defeat the whole point and b) not even work... what if the value changed? How would I get notified in a callback function that it changed? And you want me to cache the values of a million objects? x 2.
"version 3" went to LINQ expression trees and it went down to 93 milliseconds to run 1 million times. I cached the expression tree, but I did NOT cache the "expressiontree.GetValue()" calls. I still get the same property 1 million times.
4.4 seconds (or to be fair 2.1 seconds) vs 93 milliseconds is not because I'm caching anything.
propertyInfo.GetValue() is an expensive call. It gets the getter method and then calls Invoke on it. I suppose I could have gotten the getter method and cached that, but Invoke is still an expensive call.
The expression tree was simply "inline code" that essentially expanded to:
Actually, upon looking at it further in Reflector, GetGetMethod() is not expensive at all. Its already cached in the PropertyInfo object. Once you get the PropertyInfo, its already gotten the getter and cached it in a private variable. private RuntimeMethodInfo m_getterMethod; to be exact.
Invoke is very expensive since it doesn't cache a bunch of stuff, validates parameters, checks security, etc.