|
Easiest solution is to convert it to a parallel loop[^], available in .NET 4;
using System;
using System.Threading.Tasks;
class Demo
{
int N = 1000;
void TestMethod()
{
Parallel.For(0, N, (i, loopState) =>
{
Console.WriteLine(i);
if (i == 100)
{
loopState.Break();
}
});
}
}
If you need more control, you'd typically use a thread[^].
Bastard Programmer from Hell
|
|
|
|
|
I tried this code.. but i m getting high execution time than its sequential code.. and parllel execution should take less execution time than sequential code..
|
|
|
|
|
KUNWAR999 wrote: and parllel execution should take less execution time than sequential code..
..if the problem can be solved using parallel threads, and only when implemented correctly. The example was the easiest method, but it's only a shorthand for a specific type of problem.
You can spawn threads[^] to run code concurrently. It's usually the OS that decides on which core the thread runs, but I believe you can set it's affinity.
Bastard Programmer from Hell
|
|
|
|
|
i hv tried it one more way as using #pragma omp parllel ..
but vs2010 saying that its unrecognized concept..
actually i am avoiding using threads because i want to use parllel processing in processor directly..
|
|
|
|
|
KUNWAR999 wrote: actually i am avoiding using threads because i want to use parllel processing in processor directly..
..and how would you do that?
Bastard Programmer from Hell
|
|
|
|
|
Can you please explain or give a link to understand basic concept of Reflections in c#.
Thanks, Ravi
|
|
|
|
|
|
See this[^] tutorial.
/ravi
|
|
|
|
|
Reflection allows you to look at compiled .NET classes and assemblies and discover their classes and members (fields, properties, methods and events). Once discovered you can interact with these members, such as assigning values to properties etc.
It is unusual to use reflection in everyday programming. However if you were creating developer tools you may see a use for reflection.
Some classic examples where reflection is used include unit testing, documentation creation and code validation.
Reflection can also discover attributes. If you're familiar with XmlSerialization, reflection is used to read the attributes to determine which fields to serialize and which to ignore.
Others have given links for more information.
"You get that on the big jobs."
|
|
|
|
|
RobCroll wrote: It is unusual to use reflection in everyday programming
Really? Reflection is generally not known to be fast, but it can be of enormous help in many situations if used sparingly. These are my most recent examples:
I am working on my own UI and there are style objects which follow the class hierarchy of the controls. When loading a control the closest related style is found with reflection and applied to the control, even if it's a custom control with no custom style class. In that case the style of the control's baseclass is found and applied.
Also, a kind of class finder is used to decouble modules and assemblies to find specific classes and create instances of them. It uses reflection to search through the assemblies for the requested type. Let's say I'm looking for ILoginPresenter and ILoginView in order to open the application's login screen. Obtaining instances of those two would not require tightly coupled assemblies or classes. The only dependencies would be the interfaces involved.
I'm invincible, I can't be vinced
|
|
|
|
|
|
hey guys,.. i am doing my mini project in c# windows form application .. in that i used a label l in form.when
l.Text= "&";
its not showing anything on form inplace of label.
Can anyone knows solution for it??
modified 29-Mar-12 13:17pm.
|
|
|
|
|
You can try a couple of things.
(Note: I haven't tried them to make sure they all work. I just thought I'd throw out the ideas for you.)
a.Text = @"&";
a.Text = "\&";
a.Text = "& # 3 8;";
a.Text = &
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
sorry, my fault.. actually i have asked wrong question.. i have updated my question.. can u pls answer for it.. ??
thank u
|
|
|
|
|
Strange. I copy/pasted your code bit. And MessageBox displays the '&'. What version of Windows, maybe?
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
sorry, my fault.. actually i have asked wrong question.. i have updated my question.. can u pls answer for it.. ??
thank u
|
|
|
|
|
Oh, that is because the & symbol, when used in text on certain controls (i.e. buttons, menus, labels), the following character has a Mnemonic beneath it. In the designer (or in code), set the "UseMnemonic" property of the label control to 'false'.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
thnk u.. its working now..
can u tell me other text exmples which have this mnemonic beneath??
|
|
|
|
|
Anything which can take focus from an Alt+X keystroke. That is buttons, labels, menus and menu items, radio and check box buttons, groups (I think), toolbar equivalents and possibly also grid view inner control equivalents (not sure about that), off the top of my head.
|
|
|
|
|
And, I think, just putting it in as && will make it show up.
|
|
|
|
|
I think the && would, too, thanks for adding the idea. It seems like it wouldn't matter in this case but if he is actually using the mnemonics in the application it would add the line beneath the '&' that is printed on the control. Not sure if it would be a problem but it is possible.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
how can we shutdown using button
|
|
|
|
|
Push it
Failure is not an option; it's the default selection.
|
|
|
|
|
|
Push it real good
Failure is not an option; it's the default selection.
|
|
|
|