i want to call XML API from OPEN WEATHER website
and only obtain temperature, humidity and visibilty from there
then all to display in my application
which i have created in C# in MICROSOFT VISUAL STUDIO 2013
it can be displayed in text box , or label etc
and that application
and that i have built is WINDOWS FORM APPLICATION
I use Parallel.For to do some calculation, when first time i calculate, the speed is slow, but when i calculate again, the speed is better. I guess maybe Parallel.For cost time to load threading .
I want to know how to pre-load Parallel.For before calculate, so that it can be fast at 1st time.
When parallelizing any code, including loops, one important goal is to utilize the processors as much as possible without over parallelizing to the point where the overhead for parallel processing negates any performance benefits. In this particular example, only the outer loop is parallelized because there is not very much work performed in the inner loop. The combination of a small amount of work and undesirable cache effects can result in performance degradation in nested parallel loops. Therefore, parallelizing the outer loop only is the best way to maximize the benefits of concurrency on most systems.
One of the first things I always try to do when using Parallel loops is to limit the amount of processors that it could use with the following
I would like to remind you, gentle readers, that this forum was (still is to some degree) a forum for C# language issues.
I have noticed real difficulties ... for beginning students of C# ... in learning how to "strategically choose" whether to implement a method in a Class (from which other Classes will inherit) as 'virtual, or 'abstract. Of course, one factor here can be that the Class itself is declared 'abstract.
I'll spare you my own personal choices for that, here, because I'm curious what resources you've used ... or insights you've had that have led you to "heuristics" you may use now.
Appreciate your thoughts ... of any flavour !
«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.
Bill, did you mean "implement a Class ... as 'virtual, or 'abstract"? Becasue I don't think you can declare a class as virtual: MSDN[^], just properties, methods, and suchlike class components. Or am I being dumb again?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
For me when choosing between "virtual" or "abstract" depends on the situation that I am faced with, for example.
I recent had to upgrade for our insurance back office the way that premiums were calculated. I created common properties, methods in a base class using abstract to define the class as it was shared resources (properties / methods).
But because each premium calculation needed / processed the information in different ways I chose to use an abstract method to define the Premium method. It wouldn't of been useful to use a virtual as each method was different.
But if 2 of the 3 calculations would of been the same then I would of more than likely of chosen to use virtual methods.
Every day, thousands of innocent plants are killed by vegetarians.
Ahh, the use of virtual or abstract. Okay, here are some thoughts that you might find illuminating in understanding how I tend to think and decompose problems.
If a class is not abstract then you have no choice, you have to make the overridable method virtual. In this case, it means that you have a base class that is useful, in its own right, that supplies a default implementation that you might want to override. Taking a real world example, you have a car that has a number of seats - now, a seat is a useful item in its own right and should be usable as is, but you might decide that you want to provide a specialisation of bucket seats. These are interchangeable with the use of seats, but they may have special methods of fitting. So, in this case, your class structures might look like this:
// Attach using standard fitments.
publicclass BucketSeat : Seat
// Attach using the bucket seat fitments.
Now, one of the interesting things about overriding methods is the fact that you can call base. and trigger the underlying implementation. This is one of the big problems you face when you first encounter an API - do you call base. and, if so, do you call it at the beginning of your method call or at the end - an incorrect choice here can subtly alter the behaviour or your program and lead to hard to track down bugs. This is why I tend to prefer to use a specialization where I provide an empty On... or Pre.../Post... methods that are called in a predictable fashion. So, if the implementation is empty, this becomes an easy choice - if the class is abstract, make your On/Pre/Post methods abstract - if the class isn't abstract, make them virtual. Here's an example of what I mean:
// Do some work....
Note that I tend to only use the Pre/Post pattern when there is some setup/teardown options, so I might use this in a persistence module, for instance. This might look something like this:
// Do the actual save work
I find that this type of pattern removes a lot of the ambiguity that can exist in an API - obviously, there are cases where I'll just make a method virtual/abstract if there is no real implementation in the base class, meaning that calling base. would be irrelevant. I hope this helps.
It's difficult, particularly when you start - but I tend towards the "does a default make any sense?" approach.
If the base class can do something sensible and useful then it's a virtual method. If it can't, it's abstract.
So a ToString equivalent would be virtual, but a Save would be abstract.
Does that make sense?
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
Abstract methods are required; you can choose to do something in them or not. In any event, the class says: I have something to say whether you chose to respond or not. (You're out of milk; like an event?)
Virtual methods are "optional"; although if you do not override them, they "may" exhibit default behavior. The class is saying: I think something needs to be done here; I may do this if you don't override me. (Like phone 911?)
(One can still chose to run the "overridden"; like, I'll help out)
I have a Combobox with a few items. Now i will start writing in the Combobox and then only the items who fits with my writing should be shown...
for example in my Combobox are These items: "Summer, Sunshine, Winter"
so if i do nothing, all should be shown
if i write an "S" only "summer" and "sunshine" should be shown
if i write an "Su" only "summer" and "sunshine" should be shown
and if i write "Sum" only "Summer" should be shown
Long story short, you need to implement this yourself.
1. you need to keep a list of all items (originally found in the combo)
2. look for the text the user types (listed for combo's TextUpdate event)
3. recreate the combo's items, based on what the user typed; very likely, you will need to also "reopen" the combo (that is, set its DroppedDown to true)
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!