[.net] C# equivalent to signal() interrupt handling
C# gurus,
In C/C++, there's function:
signal()
-- used to set interrupt signal handling.
What is the C# equivalent?
for the most part, delegates and events are used to deal with "signal" like behavior. Null pointer references and other exceptional cases are dealt with via try..catch blocks... is that what you are looking for?
I get the impression from your last handful of questions that you are trying to port some C/C++ code to C#. If thats the case, you are going about it the wrong way.
If I recall correctly, you asked about ferror, which isnt relevent anymore to non C++ devs, you asked about direct bit manipulation in a struct ( aka int myValue : 5; ) which is barely relevant in C coding anymore let alone C++.
All I am saying is you might want to take a different approach. Doing a direct translation from one language to another is almost always a surefire way to fail. This is why so many "benchmarks" of ported C code to other languages are just frankly bad. Each language offers a different pattern which you should learn.
As the above poster said, delegates and events are ( in C# ) much better ways to deal with things in C# that coming up with a signal() equiv. If you keep down the path you are following, you will quickly come to the conclusion that C# is a crappy language based on the fact it doesnt perform as you expected. Not to mention, you havent even started to explore the advantages C# has to offer. Much as treating C++ as a better C was a bad idea in the day, treating C# as a better C++ is an even worse idea.
If I recall correctly, you asked about ferror, which isnt relevent anymore to non C++ devs, you asked about direct bit manipulation in a struct ( aka int myValue : 5; ) which is barely relevant in C coding anymore let alone C++.
All I am saying is you might want to take a different approach. Doing a direct translation from one language to another is almost always a surefire way to fail. This is why so many "benchmarks" of ported C code to other languages are just frankly bad. Each language offers a different pattern which you should learn.
As the above poster said, delegates and events are ( in C# ) much better ways to deal with things in C# that coming up with a signal() equiv. If you keep down the path you are following, you will quickly come to the conclusion that C# is a crappy language based on the fact it doesnt perform as you expected. Not to mention, you havent even started to explore the advantages C# has to offer. Much as treating C++ as a better C was a bad idea in the day, treating C# as a better C++ is an even worse idea.
I may be wrong, but interrupts are hard to handle in languages like Java and C#. When the OS sends a signal to your application, the virtual machine will receive the signal, not the app. The virtual machine then does whatever it wants to, you don't have much control over that.
EDIT: actually, catching Ctrl+C and the like is possible in .NET. Take a look at this.
EDIT: actually, catching Ctrl+C and the like is possible in .NET. Take a look at this.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement