|
Give me a break. I was away from my computer for a while.
|
|
|
|
|
Sorry, but it's just not uncommon for people to ask and then never reply when people answer by asking for more detail.
I still don't get what the conflict is - does John's answer help ? You can read the app.config as a normal XML file and parse it if you want to.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Thanks, though that isn't what I'm needing. I've replied with a bit more info.
|
|
|
|
|
If you just want to read the file, that's possible because after all, it's just an xml file. You can actually force your program to read a different app.config file but once you do, it's a fairly convoluted coding process to un-do that. I think I have some code for you to use as an example, but it may be at home.
"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
|
|
|
|
|
All right, that sounds quite weird, but that's the way it works:
foreach(something in somethingelse)
{
add_a_job_to_the_threadpool(delegate { myFunction(something.Key, something.Value); } );
}
Right, so what obviously happens here is that ALL calls to myFunction() receive the same parameters since something is passed as reference. How do I get this done as values or at least as references to the value, not to the iterator. I already tried to use a struct (which would pass by value) but the something is actually a dictionary<string,> and even wrapping them in a struct doesnt change much.
There must be a better way then copying them before passing to the delegate.
Anyone?
|
|
|
|
|
I thought you'd need to create new string variables from the Key and Value, and then pass those.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
That's what I would like to avoid. Especially since the class parameter is quite expensive by means of processor resources.
|
|
|
|
|
Yeah, I can understand that, but I suspect that the combination of how anonymous methods are scoped, and the nature of the string class, will make it unavoidable. I do think the anonymous method scoping is part of the issue, have you tried using a non anonymous method ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Actually no, didn't try that yet (more because of the custom threadpool class I am using), but to fence the problem in its worth a try. Thanks for the idea.
|
|
|
|
|
np - I hope it helps.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Andreas Saurwein Franci Gonçalves wrote: How do I get this done
That depends, there are several options. The two most obvious choices are 1) Hire a software developer that know and understands how to do multi-threaded software development 2) Learn the subject of multi-threaded software development (NOTE: this is a fairly large and somewhat complex subject ), then using the new knowledge, develop the solution yourself.
led mike
|
|
|
|
|
Thanks a lot for this quite useless answer. After 25 years developing software, about half of that threaded server applications in C++, I do have a slight idea of accomplishing this task, but I do not have sufficient knowledge of C# yet to do it.
So if you can not contribute anything useful to the forum, don't contribute at all.
|
|
|
|
|
Andreas Saurwein Franci Gonçalves wrote: So if you can not contribute anything useful to the forum, don't contribute at all.
Some people find my charming sarcasm useful. You can't please all the people all the time. So I will contribute what and when I want and not check in with your opinion. Thanks for the suggestion though. Have a nice day.
led mike
|
|
|
|
|
Andreas Saurwein Franci Gonçalves wrote: After 25 years developing software, about half of that threaded server applications in C++, I do have a slight idea of accomplishing this task, but I do not have sufficient knowledge of C# yet to do it.
Whatever. I am closing in on 20 years, with a big segment in the middle doing multi-threaded C++ server development. Someone with that background should not be struggling with such a basic issue just because the language/platform has changed.
led mike
|
|
|
|
|
Well, so as you are obviously an expert, you most surely can give an simple example in a few lines of code how to circumvent the situation. (And even if you are not an C# expert it should not be hard to answer just because its not your language of experience).
|
|
|
|
|
Andreas Saurwein Franci Gonçalves wrote: how to circumvent the situation.
Possibly, if you had described the situation accurately. As it is I can't make any sense of what you posted.
foreach(something in somethingelse) that loop is bogus, foreach(type instance <span style="color: Blue;">in</span> collection) , as is your definition of something versus how you claim to use it.
Andreas Saurwein Franci Gonçalves wrote: the something is actually a dictionary<string,><string,>
If something is a Dictionary<string, whatever> then there is no something.Key nor something.Value
add_a_job_to_the_threadpool(delegate { myFunction(something.Key, something.Value); } ); I have no idea what your requirements are nor what the existing code structure is since you obviously did not post it. Makes it rather difficult to offer any lines of code that could be helpful.
Since you appear to be struggling with how to pass the state information to each thread context. Making the following major assumptions I would say:
foreach(string skey in somethingDictionary.Keys)
add( delegate{ myFunction( skey, somethingDictionary); } ); myFunction can then obtain it's state information, or whatever it is, from the dictionary using the key
led mike
|
|
|
|
|
Thanks for confirming that you have not the slightest idea about threading and C#. You might also wish to lookup the Dictionary enumerator again on MSDN.
|
|
|
|
|
Andreas Saurwein Franci Gonçalves wrote: Thanks for confirming that you have not the slightest idea about threading and C#
Anytime. And no I have not use the new dynamic typing features in C#. After years of experiencing the benefits of strongly typed environments over untyped like javascript, I have no plans to.
I see Nick fixed your inaccurate code posting for you. That information would have been very helpful to my understanding your post.
Nick Butler wrote:
foreach( var something in somethingelse )
{
led mike
|
|
|
|
|
No he didn't fix it, just came up with something. And if you really want to see "CODE" :
foreach(KeyValuePair<string, myClass> kvp in somethingelse)
add( delegate { someFunc(kvp.Key, kvp.Value.memberXY); } );
|
|
|
|
|
Now that looks like something that would compile. So each time someFunc is executed it receives the same myClass reference? Did you solve the problem yet? It sounds like you did.
led mike
|
|
|
|
|
Both parameters are equal in all functions that did not execute yet, so if the thread pool is stopped and only started after adding all jobs, all jobs will refer to the last element in the dictionary, both key and value.
The iterator copy "seems" to solve it, I am not through with testing it yet. At a first glance it seems to work.
btw: nice that you could get down to some programmers talk finally
|
|
|
|
|
Sorry for the delayed reply. I was on vacation friday-monday.
Andreas Saurwein Franci Gonçalves wrote: Both parameters are equal in all functions that did not execute yet
Yes, that would be correct, unless you define the anonymous method to use the state of the loop.
foreach(KeyValuePair<string, myClass> kvp in somethingelse)
add( delegate (object oValue){ mytype t = (mytype)oValue; someFunc(t.name, t.memberXY); }, somethingelse[kvp.Key] ); This won't compile of course because I had to fill in unknown stuff . Also made the assumption that the object in the collection has the key as well because, at the risk of sounding arrogant (again) , that's how I would design it given my past experience developing multi-threaded applications.
Also some refactoring might be in order based on what type memberXY is.
foreach( string skey in somethingelse.Keys)
add( delegate (object obj){ mytype t = (mytype)obj; t.doWork() }, new mytype( somethingelse[skey])); The mytype ctor might need more parameters depending on it's responsibility during mytype.doWork()
Again depending on what memberXY is that, or the following, might just be shifted to memberXY or something that works with it.
Alternatively, if the doWork() responsibility makes sense for the class you already have ( the one with the .memberXY ), then the method fulfilling that responsibility could be added to it.
Andreas Saurwein Franci Gonçalves wrote: btw: nice that you could get down to some programmers talk finally
That's what I do this for. Texting does not always work for me. I did not interpret the pseudo code in your first post accurately. Seeing the actual code resolved that problem for me.
led mike
|
|
|
|
|
As I mentioned, iterator copying does the trick already. Thanks anyway for sharing your thoughts on the topic.
Restructuring so that the class would perform the job doesn't make much sense here as it would shift the whole orientation around and also give responsibility to something that shouldn't have it.
|
|
|
|
|
What an arrogant comment. A complete waste of time and space. Would you like to get that kind of response if you have a question? No, I didn't think so.
Keep It Simple Stupid! (KISS)
|
|
|
|
|
Ben Fair wrote: Would you like to get that kind of response if you have a question?
Yes. Can you give it to me now? Plezzzz, it's urgent.
led mike
|
|
|
|