|
No, you are NOT.
You are looping over the Dictionary and removing entries at the same time.
Shove them into an ArrayList and remove them AFTER completion of the foreach-loop.
Cheers
Sid
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
Perhaps I wasn't clear enough. I've got a working version that does as you described. I thought the solution was ugly and wondered if there was a better one.
|
|
|
|
|
That's not true.
You can get the Keys collection and iterate over it with a for loop:
for (int i=0; i<myDict.Keys.Count; i++)
{
object o = myDict[Keys[i]];
} Regards,
mav
|
|
|
|
|
I think that this would be more inefficient than iterating using a foreach-loop as I'm interested in removing entries according to a condition applied to the value, not the key. The foreach-loop uses the collections enumerator which probably is the most effecient way to iterate through the collection as it makes use of the collections underlying implementation. But I could be wrong though.
Please post some code that would does the same things as the one I posted if you have the time.
|
|
|
|
|
If you have runtime considerations I don't know which version is faster.
But I just wanted to counter the statement that you can't iterate over a Dictionary with a for loop.
Your original code would look something like this:
for (int i=0; i<peers.Keys.Count; i++)
{
DateTime time = peers[peers.Keys[i]] as DateTime;
if (time < DateTime.Now)
{
peers.Remove(peers.Keys[i]);
i--;
}
} (written from memory, may contain typos/bugs).
Regards,
mav
|
|
|
|
|
My statement was perhaps a bit to general. I meant that it wasn't possible to iterate through the key-value pairs with a for loop. It is, just as you say, possible to iterate through the keys and values on their own.
|
|
|
|
|
I created a class inherited from TextBox and to add it into my forms I just added Windows TextBox objects then modified the code created by VS by modifying the type to my own textbox class.
This worked fine for a while; however, all of sudded all my controls dissapeared. This must have happened because I emptied the folder that contained my custom TextBox.
So to prevent this from happening in the future, what is the right way of adding custom controls to windows forms so it doesn't wipe them out automatically?
I also have some classes inherited from "System.Windows.Forms.UserControl" and the same problem happened a while ago, so before I start creating a form with a whole bunch of my custom controls I would rather figure out how to add them the right way to prevent them from disappearing.
Please don't tell me I have to add my controls to the GAC. That would be a pain. Reason is that a while ago I added some dll's to the GAC and when I wanted to step through my code, it wouldn't step in and I couldn't figure out the reason. Finally I removed my dll from GAC and then I could go in debug mode. Maybe I did something wrong here as well, so please feel free to comment.
|
|
|
|
|
Hi;
To add your custom control on to the toolbox in VS do the following steps:
1: Create a directory somewhere on your system where you will place your custom control dll's in. Do not delete this directory or it contents. If you do the controls will not show up in your Toolbox or any forms you put them on VS.Net.
2: Go to the Toolbox and select the tab you want the control to show up on, or create a new tab by right clicking on the Toolbox and select Add Tab from the menu and fill in the tab name at the bottom of the Toolbox and press enter key. Then click on the tab.
3: Right click on the Toolbox and select Add/Remove Toolbox Items...
4: In the Customize Toolbox dialog make sure that the .Net Framework Components tab is selected and then click on the Browse... button.
5: Now navigate to the directory you created in step 1 and double click on the custom control dll you want to add.
6: Your control should now have a check mark next to it and its version number at the bottom of the page. click the OK button.
Now any time you need your control just go to the toolbox and drag it on to the form.
I hope this has been of some help.
-Fernando Soto
|
|
|
|
|
Thanks, your detailed steps sure help.
|
|
|
|
|
Hi,
I have just installed MS SQL 2005 Express for testing purpose but a unabe t gn.. what user id and passwrd should use?
Many Thanks,
Jassim Rahma
|
|
|
|
|
I don't know, but if you didn't provide a password on installation, try user name sa and leave the password blank, you probably will get in.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Hi All,
I have a problem which is driving me barmy. I am writing a VS.NET integration package which refereces a API which contains a data layer and a web control layer. When the package is loaded by the studio and I attempt to invoke a form from UITypeEditor.EditValue on a property in a web control in design mode I can not cast the value parameter (which is a type from the API) from 'object' to its correct type, the layout below might help:
1) Package Directory:
API Assembly
Package Assembly
2) VS.NET ID Directory
API Assembly (needs to be here so the property grid can load it)
3) Web Project Running in design mode with the package loaded has a reference to the API Assembly (from the IDE Folder)
In UITypeEditor.EditValue I am doing this:
Criteria c1 = (Criteria)value; // Specified Cast is not valid (also if(value is Criteria) fails)
Criteria c2 = new Criteria();
In debug, the watch reveals the the 'value' object is infact a Criteria object, however they are loaded from two different assemblys. The versions are identical, but the locations are different:
The Location for 'value' comes from a temporary projects assembly folder (more than likely created and managed by visual studio), however 'c2' is coming from the API Assembly in the VS.NET Directory. This is probably because the call is within the context of the vs.net property grid which has loaded its dll from there.
Now, I am hoping there is a correct method of getting around this!
Regards, James Simpson
James Simpson
Web Developer
imebgo@hotmail.com
P S - This is what part of the alphabet would look like if Q and R were eliminated Mitch Hedberg
|
|
|
|
|
This may lead you in totally the wrong direction, but what if you were to specify your own assembly resolver using AppDomain.CurrentDomain.AssemblyResolve?
Does this allow you to specify where to load the assembly when using the designer?
As I said, beware of wild goose chases with regards to my suggestion.
Marc
MyXaml
Advanced Unit Testing
YAPO
|
|
|
|
|
Thank You Marc,
That was successful. I removed the DLL's from the IDE directory and handled the AssemblyResolve function in the package, returned the correct assembly and the value casts as it should.
Cheers!
James
James Simpson
Web Developer
imebgo@hotmail.com
P S - This is what part of the alphabet would look like if Q and R were eliminated Mitch Hedberg
|
|
|
|
|
I was looking through some dll's using dependancy Walker and alot of them are pointing toward a Watchdog.sys file. Looking through this file I see alot of monitoring and event functions.
What exactly does this file monitor?
And is there a way to interop into it from C#?
Thanks
Steve
Steve Welborn
Software Architect
|
|
|
|
|
I have been developing a Soap messaging application. I created a message handler class which was derived from from the SoapReciever class. I created a node by putting the class in my web server and added it to the web config file under httpHandlers. I can send soap messages and the recieving end is intended to write the messages to an XML file, the code is correct however in the end there is no file.
Does anyone know what I should do?
|
|
|
|
|
Hi , C# Fellows,
I am writting a program to deal with C++ Dll.
When I do stress testing , (run the program continously), at the end I got "Out of Memory" Exception , So I am thinking of adding some code to monitor memory change. But the prolem here is , I dont know when the Garbage Collector will kick in. So , Its critical to catch this event.How Can I do it in C#--???
Thanks
|
|
|
|
|
Is there something wrong with using the Performance Monitor built into Windows?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Well, stress testgin will last for a quite long time , and I can't stay there stare at it whole day.
|
|
|
|
|
It can log the data to a Perofmrnace log file. But since, in your other post, you said that you want to log what looks like every function call, Performance Monitor won't help you.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
hi, Leppie,
I make it clearer:
what I want is a record something like this:
time:- 8:12:21, Event : function ..called,free memory size: ..Bytes
time:-8:12:23, Event : GC called ., free memory size : ..Bytes;
so later on we can determine which function does have memory leak.
and ,Yes , some Dll call locate memory and release later.
|
|
|
|
|
Technically I don't think it is ever specified when the GC happens (no behavior in the ECMA is specified for this?) and technically you as a .Net Framework programmer shouldn't care. There is no real concept of "memory" in a virtual machine like the .Net Framework. An object holds a "reference" not a memory address. Memory is treated just like other resources (file handles, sockets, etc). The virtual machine can either allocate the resources necessary to vivify (is that the right word? ) the object or it fails and hopefully throws an exception that is meaningful.
So from what I read you want C# code that knows when it can't create any more objects. This is inherently hard to do in a virtual machine system like the .Net Framework because all of the innards are virtual! In general the .Net Framework will not tell you before hand whether you can create the object before you create it. You can gather some information about the external OS and try to make a judgement then but I haven't found a .Net Framework facility to check if it will succeed making the next object beyond trying to make the next object.
ps. Since it sounds like you are dealing with a DLL written in C/C++, maybe you are leaking memory because you aren't handling allocation correctly? If you fix that you don't need to worry about trying to monitor memory usage.
|
|
|
|
|
You can use the CLR Profiler[^] to get this type of information, or if it doesn't work for you, you can write your own profiler that ties into the .net profiler api to get that information.
I can imagine the sinking feeling one would have after ordering my book,
only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon
|
|
|
|
|
Is there any utility which converts VC++ code to C# code. I do not expect all conversions basic conversion will do such as class, property, method migration.
Thanks
Shyam
|
|
|
|