|
Hi fellows
My question is simple:
I have a very little program that I've created to understand the IEnumerator interface.
Here is a little piece of my software
//Method to populate my array
private void PopulateArrayList()
{
for(int i = 0 ; i < 4 ; i++)
{
m_MyDoors.Add(new Doors());
}
}
public void WhatDoorsIsOpened()
{
object CurrentDoor;
int i = 1;
IEnumerator NumberedDoors = m_MyDoors.GetEnumerator();
while(NumberedDoors.MoveNext())
{
CurrentDoor = NumberedDoors.Current;
if(((Doors)CurrentDoor).OpenClose() == false)
{
Console.WriteLine("Door {0} is opened.", i);
i += 1;
}
else
{
i += 1;
}
}
}
I've read in MSDN that IEnumerator supports a simple iteration over a collection. In this line of code:
IEnumerator NumberedDoors = m_MyDoors.GetEnumerator();
I'm just assigning the m_MyDoors' IEnumerable typed collection in the NumberedDoors, right?
In the MSDN too the following was wrote about IEnumerable:
Exposes the enumerator, which supports a simple iteration over a collection.
I've understand that IEnumerator assigns a typed collection.
I did'n understand so good the IEnumerator. The IEnumerable I didn't understand nothing?
Can anyone helps?
Thanks
|
|
|
|
|
Hi.. I'm currently doing a web design on the calendar. I would like to ask that if i click the date on the calendar, how can i make it appear on the text box once i click on the date? I have tried several ways of doing it but it does not show out. Did anyone know how to call the date out onto the textbox? Your help will be greatly appreciated.Thank
Cheers!
|
|
|
|
|
You need to make your calendar control auto postback on selection, then set it in your codebehind.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
it seems that my program hangs (freezes) until the process that was started ends... how can i start a program without waiting for it to end?
thanks in advance,
sam kline
also, i have another noob question... how do i post code snippets (showing the code in a table)
|
|
|
|
|
Sam,
That's pretty wierd about the Process . It shouldn't cause your main app to hang. On the other hand, starting a new process is pretty expensive in the overall scheme of things. If you start a short-lived process, the time that the system takes to create the new process and start the application in it can overshadow the short run-time of the actual application. Do you think that you can post a little code snippet to show us in what context it's occurring?
To answer your second question, you can wrap some code in <pre> tags, like:
<pre>Code goes here.
And, this is indented. Nice, eh?
</pre>
becomes
Code goes here.
And, this is indented. Nice, eh?
Or, when you post your comment, under the emoticon row, there is a checkbox that essentially wraps your entire post in PRE tags.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
-- modified at 18:08 Wednesday 23rd November, 2005
|
|
|
|
|
Hello everybody.
I have a class A that publishes an event, and is using a delegate to allow other objects to subscribe to it. After raising the event, class A is sending some information wrapped up in the custom class deriving from EventArgs. When the event fires, the class is then going through the list of subscribers using the GetInvocationList() and is getting the response from the subscribers.
So far so good.
The problem is when trying to subscribe to the event from a class B that has no reference to class A.
It would be easy enough to add a reference to it and to just subscribe to the event, however we do not want to make the server code to reference the client classes.
Is there a way to do this differently? If not, that what about adding an intermediary object that can receive and pass on the events raised in class A on the client side, so that class B on the server needs only to reference one object* But if there's a better way then I would really appreciate some directions.
Thanks a lot.
Sarajevo, Bosnia
-- modified at 15:21 Wednesday 23rd November, 2005
|
|
|
|
|
mirano wrote: The problem is when trying to subscribe to the event from a class B that has no reference to class A.
It would be easy enough to add a reference to it and to just subscribe to the event, however we do not want to make the server code to reference the client classes.
You could make the event handler in Class B public and have a mediator class attach it to the event in Class A.
Or have an interface represent only the event that's in Class A that Class B needs to subscribe to. Hopefully, the event represents something easily identifiable so that it's easy to name.
Have Class A implement this interface. Pass an instance of Class A to Class B as a reference to the interface, not Class A. This way, Class B only knows about the interface. This decouples Class B from Class A.
mirano wrote: If not, that what about adding an intermediary object that can receive and pass on the events raised in class A on the client side, so that class B on the server needs only to reference one object*
I would go the interface route first. The interface is in essence doing the job that your intermediary object is doing, only basically for free.
-- modified at 17:47 Wednesday 23rd November, 2005
|
|
|
|
|
Thank you for your help, Leslie. I will give it a try today. The solution seems reasonable and I was thinking about the interface when I meant intermediary object, just everything is kinda upside down - the server is to subscribe to the event that the clients would raise.
The solution with the interface is a common one, but still I wanted to see is there some other pattern that we should use when going with a delegates, event though I could not remember seeing any such implementation.
The easiest way is to add a reference to the server, but doing that and in a short time the server implementation gets bloated with too many assemblies.
Thanks again.
Sarajevo, Bosnia
|
|
|
|
|
mirano wrote: The easiest way is to add a reference to the server, but doing that and in a short time the server implementation gets bloated with too many assemblies.
I can understand that.
If you do try the interface approach, you may want to put it in the server library/assembly. I'm assuming you have a server assembly and various client assemblies that use the server. In this situation, it's understandable that you wouldn't want the server referencing the clients to avoid assembly bloat, but also to avoid a circular dependency as well.
You could put a IClient interface (or whatever name seems appropriate to you) in the server library. It would represent the basic functionality the server needs to interact with its clients regardless of where or who they are. In this interface would be the event you described earlier. Client libraries would implement this interface and could register themselves with the server; something like a server.Connect(IClient client) method in which the server subscribes to the event in the IClient interface.
Alot of what I've described above is based on some assumptions that may not be true for your situation. At any rate, if it's helpful at all, cool. Just my 2 cents.
|
|
|
|
|
Could not get it to work.
Here's the problem: Class A implements the interface IClient that is on the server, everything's fine. When the method Foo of the class A is executed, the event is raised, passing some data class as a reference. Now, in order to subscribe to the event from the server, I need to do something like this:
Foo f = new Foo();
IClient icl = f as IClient();
and then:
icl.SomeEvent += new ... bla, bla...
but I DO NOT HAVE a reference to class A, method Foo, which is the whole point from the very beginning. Is there another way to subscribe to the event that is wrapped in the interface without having to know the class that's implementing it on the client side?
Thanks.
Sarajevo, Bosnia
|
|
|
|
|
You can have a reference to Class A on the server side without knowing its type as long as it implements an interface the server knows about and the reference is passed as a reference to that interface type.
Let's look at a bit of code so that what I wrote above is more concrete.
In the server library, you have the IClient interface:
public interface IClient
{
event EventHandler ClientChanged;
}
Also, we have the Server class:
public class Server
{
public void Connect(IClient client)
{
client.ClientChanged += new EventHandler(HandleClientChangedEvent);
}
public void Disconnect(IClient client)
{
client.ClientChanged -= new EventHandler(HandleClientChangedEvent);
}
private void HandleClientChangedEvent(object sender, EventArgs e)
{
}
}
Now, the Server can attach and detach itself to the client's event without having to know its type. All it knows is that the client implements the IClient interface.
Make sense?
On the client side, we do have to know about the server, but the dependency is one-side, i.e. not circular, so we're ok:
public class SomeClient
{
public SomeClient(Server s)
{
s.Connect(this);
}
}
-- modified at 13:12 Saturday 26th November, 2005
|
|
|
|
|
Yes, you are right. It works. It was just not that obvious how to get the client throught the interface in order to subscribe to the event.
Thanks.
Sarajevo, Bosnia
|
|
|
|
|
Seems the only reasonable way of playing a sounds - such as a .wav is to go back down to Win32?
Am I right or wrong.
"Je pense, donc je mange." - Rene Descartes 1689 - Just before his mother put his tea on the table.
Shameless Plug - Distributed Database Transactions in .NET using COM+
|
|
|
|
|
Giles wrote: Seems the only reasonable way of playing a sounds - such as a .wav is to go back down to Win32?
System.Media[^]
|
|
|
|
|
I guessed there would be something like that. Problem is .NET 1.1.
I've currently got a third party lib, and it does not like 2.0, as its a wrapper for a C++ class, linked to the 7.1 C++ runtime.
Sorry, should have been more specific.
"Je pense, donc je mange." - Rene Descartes 1689 - Just before his mother put his tea on the table.
Shameless Plug - Distributed Database Transactions in .NET using COM+
|
|
|
|
|
Giles wrote: I guessed there would be something like that. Problem is .NET 1.1.
I've currently got a third party lib, and it does not like 2.0, as its a wrapper for a C++ class, linked to the 7.1 C++ runtime.
Ah, well in that case, yeah, looks like platform invoke is the way to go. If you just need simple .wav playback, the sndPlaySound looks like it could do the job for you.
If you need some help in this area, let us know. I've had some experience wrapping the MIDI API, so I may be able to give you some pointers on wrapping the sndPlaySound function, or probably someone here at Code Project has already done it.
|
|
|
|
|
Leslie Sanford wrote: If you need some help in this area, let us know. I've had some experience wrapping the MIDI API, so I may be able to give you some pointers on wrapping the sndPlaySound function, or probably someone here at Code Project has already done it.
Thanks. I saw the artiles on CP. Seemed pretty straight formward, and I've used the MM library before from CPP.
Was just hoping there was a cleaner way. Nice to know the've fixed it of sorts for the future.
"Je pense, donc je mange." - Rene Descartes 1689 - Just before his mother put his tea on the table.
Shameless Plug - Distributed Database Transactions in .NET using COM+
|
|
|
|
|
Is there any one that can point me in the right direction on how to create a generic printer driver, or is there a walktrough on who to create a printer driver.
I would like a generic printer driver that a can handle the flow of chars and do wath ever a mant with them.
|
|
|
|
|
Not in C# you don't.
For the time being you need to use very low level C++, using the Driver Development Kit or DDK.
There are some good articles on CP about an introduction the black art of driver development.
Saying that in future, becuase so many printer drivers are badly written in Windows Vista, MS is going to make all printer drivers user mode.
http://www.microsoft.com/whdc/devtools/ddk/default.mspx[^]
Saying that you could probably fudge it using a serial cable, or even a netowork based printer, but not by using USB port.
"Je pense, donc je mange." - Rene Descartes 1689 - Just before his mother put his tea on the table.
Shameless Plug - Distributed Database Transactions in .NET using COM+
|
|
|
|
|
is there a way i can move the mouse to position (x,y) when a function is called?
|
|
|
|
|
Use Cursor.Position from the Winforms namespace.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
|
I am having a lot of problems with source safe going very slow pulling files. I'm using NAnt to do a GET and build my application. The application consists of about 1000 files, and it takes nearly 10 minutes just to get the files to the server to build. Does anyone else experience this?
Also, how can I make it just pull the changed files? I have another project which contains about 5000 xml files and it takes over an hour to pull all of these, when only 30 have changed. There has to be a way to pull only these 30 in a matter of less than a minute.
Thanks!
Curtis
|
|
|
|
|
glocklt4 wrote: Does anyone else experience this?
Everyone. And that's why anyone with at least a mid-sized project or more than 3 or 5 person working on the same projects migrate to other VCS, like CVS, SVN, Perforce, Bitkeeper, etc.
I see dead pixels
Yes, even I am blogging now!
|
|
|
|
|
So there is now way to make it really only pull the lastest files?
GREAT!!
|
|
|
|
|