|
|
BestSnowman wrote:
Is it possible to use IO Completion Ports in C# or MC++?
That depends on what you want to do, as the link AK gave you says IOCP isn't exposed directly by the framework. But Eric Gunnerson[^] confirmed in the early days of this forum that if IOCP is available the BeginRead /BeginWrite methods on the various Stream classes will make use of it.
[edit]The thread[^][/edit]
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
Hi,
I'm a newbie in the C# world, having arrived from MFC land. I'm learning about C# and .NET by playing around with a Windows Form app. I'm also in the process of porting one of my CP articles to .NET.
Anyway, my question:
I've added an event handler to a control in the form, and would like it to do nothing in some circumstances -- in other words I want it to just call the parent's event handler. How is that done when it comes to events and delegates?
For example, I know that with MFC, if override the IDOK handler (OnOK), I can just call CDialog::OnOK to let it do its default behavior. But events in C#/.NET seem to work differently.
I appreciate your help.
Regards,
Alvaro
When birds fly in the right formation, they need only exert half the effort. Even in nature, teamwork results in collective laziness. -- despair.com
|
|
|
|
|
Rememebr that you must override the method that generates the event. You're not in fact overriding the event. For example the OnClick method raises the Click event. The OnClick method is virtual and therefore can be overriden. To call the default you simply would call the base's OnClick method ie base.OnClick(). For example:
protected override void OnClick ( System.EventArgs e )
{
base.OnClick(e);
}
|
|
|
|
|
Thanks nero. That clears up a lot of things. I wasn't aware of the OnWhatever members, but now it makes sense. They get called whenever something happens and their job is to trigger their specific events via their respective delegate members. Cool!
So now then, let's suppose I have a form, and I decide to handle the Click event of one of my buttons. In this case, the code inside the OnClick method will execute independently. In other words, my event handler is just a notification that something happened; it doesn't give me any control over whether to still execute the parent's code or not. But what if I did want that type of control? Would I have to derive my own Button class and override the OnClick?
Thanks again,
Alvaro
When birds fly in the right formation, they need only exert half the effort. Even in nature, teamwork results in collective laziness. -- despair.com
|
|
|
|
|
It would be a mistake for you not to call the parent's code, just as it is in MFC. Can you imagine if you override the OnPaint event and not call the parent's code. That would be dangerous, because the parent code most often than not is critical for it to function properly.
That being said however, if you really don't want to call the parent's code, then yes, you would have to derive your own Button class and override the OnClick.
Cheers
|
|
|
|
|
Alvaro Mendez wrote:
would like it to do nothing in some circumstances -- in other words I want it to just call the parent's event handler.
The pattern Microsoft uses (in all instances I know of) is the following:
Class Foo exposes an event named Bar, Foo also has a protected method called OnBar. OnBar does two different things, one is a side-effect of the other.
First, in the class that defines the event OnBar can include some processing but to my knowledge they just fire the event, leaving the processing to however that class calls OnBar. The Bar event is fired from within OnBar because events can only be fired while operating within the class that defines it, anywhere else you can only add or remove handlers.
The second thing that OnBar does is allow you to handle the Bar event without having to hookup another event handler, reducing a little overhead (though not much).
Because OnBar should only fire the event, you can also call OnBar yourself to fire the event outside of normal circumstances.
Another thing to note is that events (for the most part) are notifiers that something has happened so you can only respond to that thing happening. As you suggest later, in order to prevent the Click event from firing in certain circumstances you need to go to the source, the OnClick method, and not call base.OnClick in those cases.
Hope that makes some sense to you, my thoughts have been jumbled a bit lately.
James
"It is self repeating, of unknown pattern"
Data - Star Trek: The Next Generation
|
|
|
|
|
I am using Visual Studio .net to try to make a button work like a ReadLine method.
I am using the button along with a textbox. The button is supposed to confirm the textbox after I have typed something in. I then want the textBox to stop reading after I have clicked the button and the information has been submitted. Then it should work again.
I'm using the Button event handler but that only works one time.
|
|
|
|
|
Hello,
I am attempting to create a custom class that is inherited from XmlNodeList.
public class MyNLClass : XmlNodeList
{
public string MyFunction(string name)
{
}
}
I would like to add a few additional functions. when I create class, I am getting errors like:
MyNLClass' does not implement inherited abstract member 'System.Xml.XmlNodeList.Count.get'
MyNLClass' does not implement inherited abstract member 'System.Xml.XmlNodeList.GetEnumerator()'
MyNLClass' does not implement inherited abstract member 'System.Xml.XmlNodeList.Item(int)'
Any help would be appreciated.
Thanks
|
|
|
|
|
The XmlNodeClass is cannot be created. Notice that the constructor is protected. Therefore this class was meant to be inherited from. Basically the class is essentially abstract and so are the members for which you are receiving errors.
Therefore, if you inherit from this class, you must implement all methods and properties that are abstract on this class. ie you must define these methods in your class. That is why you are getting the above errors. It's complaining that you haven't implemented them.
|
|
|
|
|
This more for my curiosity than efficiency, necessarily.
Is there a more straightforward way to get the fully qualified domain name of the machine the process is running on?
This is what I have so far, and it works:
<br />
System.Net.IPHostEntry ipEntry = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName());<br />
String hostName = ipEntry.HostName;<br />
In my case, at least, System.Net.Dns.GetHostName() returns just the name of my computer, not the domain name, too.
|
|
|
|
|
I need to create two different classes which differ only in the data member types. The first class is an "IntegerPoint" class, using integer values for the x and y. The second class is a "DoublePoint" class, using double values for the x and y.
These classes have extensive operator, method, etc. functionality. But all of the functionality is identical, again the only difference is the data member type.
Does anyone know what the "best practice" is for handling this type of situation? Can some form of inheritance be used here?
Mark Sanders
sanderssolutions.com
|
|
|
|
|
first a question:
do you need two implementations - are you having two because you are worrying about performance?
why not just have a DoubmePoint class - see if you have a problem then.
if that does not work then:
create a class called SanderNumber which can use either a integer or a double.
then create your abstract class SanderNumberUtil that uses SanderNumber.
then create a concrete class for integer and double.
This puts most of the complexity into SanderNumber - but allows you to use it polymorphically.
hope this helps.
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
why not just have a DoubmePoint class
I am not sure what you mean by "DoubmePoint class".
if that does not work then
I somewhat understand the theory of what your second solution is but I also can't really invision it very well. Could you give a little more detail?
Mark Sanders
sanderssolutions.com
|
|
|
|
|
type - i meant why not just have the DoublePoint class - do you really need the integer class?
otherwise
class SanderNumber
{
bool _isInteger = true;
int _valueInt;
double _valueDouble;
public SanderNumber(int value)
{
_valueInt = value;
}
public SanderNumber(double value)
{
_valueDouble = value;
_isInteger = false;
}
public int SomeFunction()
{
// if (!_isInteger) throw(some exception)
return _valueInt;
}
public double SomeFunction()
{
// if (_isInteger) throw(some exception)
return _valueDouble;
}
}
class SanderUtil()
{
SanderNumber _number;
public SanderNumber(SanderNumber value)
{
_number = value;
}
public SomeCleverStuff()
{
if (_number.SomeFunction()) > 24.0)
return;
}
}
this would give you what you want and would be type safe.....
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
You could implement an Interface for your methods which the two classes will inherit and have to implement. That is if the implementation of the methods are different.
|
|
|
|
|
|
you could make the integerPoint class, then derive the doublepoint class from that, and override the variables/properties inherited....just a thought.
| Website: http://www.onyeyiri.co.uk
| Sonork: 100.21142 : TheEclypse
| "If a dolar was a chicken would the chicken be evil?"
|
|
|
|
|
I'm writing my first C# Windows Application using Win Forms. The program, a simple utility, is very processing intensive. Once the processing begins it continues for several minutes.
I need the program to process UI messages while it is processing data, obviously. I'm not sure how to do this using the runtime.
Would some kind person please point me in the right direction?
Roger
|
|
|
|
|
Well this involves some long explanation. It involves some windows understanding before you begin. What's important is that once the process is finished , it must call back on the windows message loop's main thread. I have the perfect article for you. Tale the time to read it. It's worth it.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp
|
|
|
|
|
My first thought would be to use the System.Threading class. Simply set you processing function as a thread and let it run simultaneously as your main thread.
Notorious SMC
The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning
Mark Twain
Get your facts first, and then you can distort them as much as you please
Mark Twain
|
|
|
|
|
The problem here is what happens if you want to be notified, when your thread is complete. That may be the case for many UI apps.
The article I have mentioned explains all this.
Cheers
|
|
|
|
|
Well, just add a MessageBox function add the end of the method that contains your process
Notorious SMC
The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning
Mark Twain
Get your facts first, and then you can distort them as much as you please
Mark Twain
|
|
|
|
|
Not exactly. Again, in most cases you want to do more than add a message box. Say for instance that when the process is finished, you want to write something to a textbox on that form. You MUST NOT update the textbox in the new thread. That is a no no in Windows. You must only update controls on the windows main thread (the win proc).
The article I've already mentioned explains all this. Take the time to read it, it's informative and it helped me alot as well.
|
|
|
|
|
Cool. Will look it up.
Notorious SMC
The difference between the almost-right word & the right word is a really large matter - it's the difference between the lightning bug and the Lightning
Mark Twain
Get your facts first, and then you can distort them as much as you please
Mark Twain
|
|
|
|