|
Lets copy file in asynchronously
FileStream sourceFile = new FileStream(.....);
FileStream destinationFile = new FileStream(....);
byte[] buffer = new byte[BUFFER_LENGTH];
AsyncCallback readCallback = null;
readCallback = delegate(IAsyncResult readResult)
{
int byteRead = sourceFile.EndRead(readResult);
destination.BeginWrite(buffer,0,byteRead,new AsyncCallback(delegate(IAsyncResult writeResult)
{
desitnationFile.EndWrite(writeResult);
destinationFile.Flush();
sourceFile.BeginRead(buffer,0,buffer.Length,readCallback,null);
}),null);
};
sourceFile.BeginRead(buffer,0,buffer.Length,readCallback,null);
|
|
|
|
|
Sytem.IO.File.Copy("Try reading the books","or use Google, lazy")
Bob
Ashfield Consultants Ltd
|
|
|
|
|
I know that C# doesn't directly implement it, though I found an article that describes a way to kludge around it, but I was just wondering whether anyone is still pursuing it. Back when I was doing Turbo Pascal semi-OOP programming it was the hot topic, but things have got a bit quiet since then. Does any language still support it?
Yeah, I know it's not directly relevant here, but I'm fiddling with a model for an electrical substation and looking at C# as an possible implementation language. Substations contain transformers, regulators, reclosers and breakers, and some transformers have the regulators built in, so it seemed a natural fit for MI. On closer inspection, it's not worth the trouble, but I'm still curious whether anyone is still trying to make it work.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
C# and Java don't, and it's unlikely they will in the future either. You can use interfaces instead.
Maybe VB.NET does support MI, I have no idea. Not sure if you want to go down that road....
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|
|
The CLR does not support MI, so no language that runs directly in the CLR will be able to use MI.
(Well it is possible to generate interfaces and implement those at compiletime, but the actual code would not be true MI)
|
|
|
|
|
Thanks, Roger.
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|
|
If the state of the art hasn't improved significantly since 1994, I'd guess MI is more hassle than it's worth.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Roger Wright wrote: Does any language still support it?
Many OO languages support it. C++ for example.
Roger Wright wrote: transformers have the regulators built in, so it seemed a natural fit for MI.
Would a composite object (i.e. it has as member variables a Transformer and a Regulator) be better? You could create an ITransformer interface and an IRegulator interface and have the composite implement both interfaces which just passes it down to the relevant object.
You may be interested in a blog post I wrote a while ago on Mixins (a type of MI) and how to implement it in C#: Mixins in C#3.0[^]
|
|
|
|
|
Thanks - that might be a good approach!
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Multiple inheritance is dead. If you want to do real programming, you have to stick with a real language.
I actually used multiple inheritance in MFC apps. In my particular case, I had to extend a base class, but I didn't want to actually change that class (I forget the specifics, but that's the gist of it). I simply added some data members and methods in a new class that was NOT derived from CObject, and changed the prototype for the derived class to inherit from it as well as the original base class. It work a treat and was the object of may ooohs/aaahs among the rest of the programming team because it was the first time they'd seen multiple inheritance used outside the classroom.
I guess what I'm trying to say that it wasn't widely used in C++, and Microsoft probably realized that. You're going to have to more carefully design your classes as a result, though.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: Multiple inheritance is dead
If it isn't, it probably should be. I remember playing with it in a 'real' language (pascal) and it really was a royal PITA to get right.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
Multiple-inheritance is a problem in C++ when more than one base class share a common base class. For example, your class E derives from B1 and B2, and B1 and B2 both derive from A. Should your class E have one or two copies of A? The C++ answer is two, unless B1 and B2 declared A as a virtual base class, in which case they share a common set of A's members. My recollection is that this causes some other problems, though I can't recall what they are now. Something to do with construction, perhaps?
For more on this and how some other languages solve the problem, see Diamond problem[^] on Wikipedia.
Anyway, due to C++'s problems in this area, the designers of Java and then C# decided to explicitly separate out interface inheritance from base class inheritance, and only allow a single base class. C# allows explicit interface implementation in case of method name conflicts.
DoEvents: Generating unexpected recursion since 1991
|
|
|
|
|
It sounds like C# is equipped to solve the problem, but MI is not the way to go. I'll look more closely at the C# approach using interfaces. Thanks!
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
I can connecto to some machine by using FTP connection.
On this machine i hold some Batch file - and i want to run some of those batch file from my machine ( the batch file will run on the remote machine ).
I mean that i need to run this batch file and its need to be same as i using explorer to see the batch file that are on this remote machine and double click on some batch file that i see on this machine.
Thanks for any help.
|
|
|
|
|
private void InitMenu()
{
DevComponents.DotNetBar.BaseItem[] baseitem = new DevComponents.DotNetBar.BaseItem[menuStrip1.Items.Count];
System.Windows.Forms.ToolStripMenuItem submenuitem = new System.Windows.Forms.ToolStripMenuItem();
for (int ii = 0; ii < menuStrip1.Items.Count; ii++)
{
try
{
baseitem[ii] = new DevComponents.DotNetBar.SideBarPanelItem();
baseitem[ii].Name = menuStrip1.Items[ii].Name.ToString();
baseitem[ii].Text = menuStrip1.Items[ii].Text.ToString();
submenuitem = (ToolStripMenuItem)menuStrip1.Items[ii];
DevComponents.DotNetBar.ButtonItem[] buttonitem = new DevComponents.DotNetBar.ButtonItem[submenuitem.DropDownItems.Count];
for (int i = 0; i < submenuitem.DropDownItems.Count; i++)
{
if (submenuitem.DropDownItems[i].Text == "" || submenuitem.DropDownItems[i].Text.Trim() == "-") { continue; }
DevComponents.DotNetBar.ButtonItem blnitem = new DevComponents.DotNetBar.ButtonItem(submenuitem.DropDownItems[i].Name, submenuitem.DropDownItems[i].Text);
blnitem.ButtonStyle = DevComponents.DotNetBar.eButtonStyle.TextOnlyAlways;
blnitem.ImagePaddingHorizontal = 8;
//blnitem.Click += new System.EventHandler(submenuitem.DropDownItems[i].Click); // how to bind the relative menu event to blnitem
blnitem.ImagePosition = DevComponents.DotNetBar.eImagePosition.Top;
baseitem[ii].SubItems.Add(blnitem);
}
sideBar1.Panels.Add(baseitem[ii]);
sideBar1.Refresh();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
|
|
|
|
|
Hello everyone,
Since DateTime is struct other than class, each time when we use DateTime abc = DateTime.Now, there are two copies of DateTime structs?
1.
One instance is created by DateTime struct internally, which represents the current time, and another instance is copied from the internal instance to the value type variable abc when we perform assignment operation?
2.
I think the internal instance is a waste? Since it is useless when the value is copied to variable abc?
thanks in advance,
George
|
|
|
|
|
Well, if you call it twice, the time will have probably changed....
George_George wrote: I think the internal instance is a waste? Since it is useless when the value is copied to variable abc?
You ask a lot of really bizarre questions. If I do DateTime.Now, I get a variable which stores the time I called it. If I keep that variable about, it's because I want to store that time. If I call it again, I want to get the time now, not the time I last called it.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks Chris!
So, you agree with my points (1) and (2) in original question post? And DateTime abc = DateTime.Now statement will create two copies of values?
regards,
George
|
|
|
|
|
George_George wrote: And DateTime abc = DateTime.Now statement will create two copies of values?
No. It will look up the current datetime and store it in a value. There's no collection of values for every possible datetime, they get created as you ask for them.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I agree, Chris!
But, since DateTime is a value type, so, there should be an internal copy of current time created by struct DateTime struct itself, and during assignment to variable abc, abc is another copy of "current time", so there are two copies, right?
regards,
George
|
|
|
|
|
George_George wrote: But, since DateTime is a value type, so, there should be an internal copy of current time created by struct DateTime struct itself, and during assignment to variable abc, abc is another copy of "current time", so there are two copies, right?
If DateTime is a value type, then it's going to be copied when it is returned. You're talking about a collection of a handful of ints. I don't see that as a big deal, do you ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I agree with you Chris. My purpose is just to understand how things work from CLR principle. BTW, you mentioned -- "collection of a handful of ints", you mean the DateTime is represented by a couple of int type and the foot print is small?
regards,
George
|
|
|
|
|
Does it really matter? With all the bloat built into Windows and .NET in general whats a few bytes here or there
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hi Bob,
I just want to practice my understanding of C# concepts.
regards,
George
|
|
|
|
|
DateTime.Now is a static property and returns a new instance of a DateTime object. The only thing in memory is the newly allocated (and returned) DateTime object.
Stop over-analyzing this crap and do some real work.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|