|
for this to work, GetProcessFromSystem() has to return an IEnumerable. If it does, the foreach will be happy. However, if the enumerable would change while foreach is iterating over it, an exception would be thrown.
Whether GetProcessFromSystem() implements and returns the information you hope to get cannot be determined without seeing it.
|
|
|
|
|
Luc Pattyn wrote: Whether GetProcessFromSystem() implements and returns the information you hope to get cannot be determined without seeing it.
If you want, it returns List<Process> , every time is called. If some app would crash and dissapear. Everytime this method calles, it construct the list from scratch. The only wory for me is that it wouldn't dissapear from the list, while it is in loop. It seems i am going to localize it first before passing to foreach loop.
Also that method is a standart as you would get the same list from task manager
|
|
|
|
|
When the method is returning a List, and no one is altering the list, then the list remains as is. Some process crashing, being killed or getting started will not modify the list.
If you don't understand or don't trust how foreach works, then I can only suggest you study it, or stop using it.
|
|
|
|
|
Assuming, for the sake of this answer, that GetProcessFromSystem() returns a List<Process> it would be better to do:
List<Process> procs = GetProcessFromSystem();
foreach (Process proc in procs)
{
............
............
}
Doing it the way you first proposed would be more greedy for system resources as (I think) GPFS() would be called on each iteration of the foreach loop, consuming resources. In addition the list could easily change, items might be added or even removed. Anything implementing <code> IEnumerable can give unpredictable results, especially if things are removed from the list.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Can't agree with that.
In for (int x=0; x<bitmap.Width; x++) the Width property is fetched over and over, once per iteration, and returning the same value all the time; so it makes a lot of sense to use a local variable.
Inforeach(type someVar in someExpressionYieldingAnEnumerator) the expression is evaluated once, and the resulting enumerator is worked with (i.e. its MoveNext method is called once per iteration). Using a local variable for holding the enumerator does not change a thing, except it adds to the typing and the risk of errors.
|
|
|
|
|
Thanks!
I stand corrected. (Well actually I'm sitting)
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
still facing South?
|
|
|
|
|
Yup, I haven't rearranged the furniture.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Henry Minute wrote: Doing it the way you first proposed would be more greedy for system resources as (I think) GPFS() would be called on each iteration of the foreach loop,
No, it wouldn't. Your code is functionally identical to the OP's code. The code in the foreach's paranthesis is executed only once and the code in the curly braces is executed for each item in the collection returned by the paranthesis code.
Now, if the collection we modified by a background thread or by the code in the curly braces, then you've got a problem...
|
|
|
|
|
Thank you.
I'll try to remember that and probably fail.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Then what's with the elephant??
|
|
|
|
|
foreach(Elephant I in GetMyZoo()) I.CantRemember();
|
|
|
|
|
The Elephant is Henry Minute.
I have to do the typing for him because we cannot find a large enough keyboard.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
You should buy him an iPhone then. There is this little app that lets him trumphet in morse code, each character gets translated automatically in a regular keystroke.
If he dislikes the iPhone (or when the neighbors object), there is an alternative based on a Wii Fit. That requires flapping the ears, this time using what amounts to the semaphore alphabet.
|
|
|
|
|
We tried your second suggestion. Never again.
He got a little excited once and it took 3 weeks and a whole case of baby-oil to get his ears untangled.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
is there a YouTube reference, or any other proof of bodily harm, discomfort, or damage; so others could benefit and maybe start a class action suit against Nintendo?
|
|
|
|
|
Hi everyone.
I´m on the hunt for some good code examples on how to convert a bitmap file (In my case a monochrome bitmap) to an ASCII string.
This ASCII string will be sent to a QLS-printer to be printed.
There must be someone who has run in to the same problem as myself, would anyone like to share his/her experience?
Thanks!
|
|
|
|
|
Don't you have the driver that goes with your printer? Try this[^].
BTW: I fail to see how an image would need to be converted into an ASCII string.
And what would you do if you had such string? It would print as text anyway.
|
|
|
|
|
I actually don't have access to the printer at the moment to be able to test and the thing is that the printer can handle either the .PCX file format or ASCII format. According to the project specifications I must convert the .BMP-file I have to ASCII.
|
|
|
|
|
Then you should hunt for the printer's documentation. Although I still think getting the proper driver is the right way to go.
|
|
|
|
|
ASCII is text. So define how this image is supposed to be "converted to ASCII". Are you talking about "ASCII art"? Are you saying that the printer understands some bitmap format and the image has to be converted into a string of commands that the printer understands in order to printer the image?
|
|
|
|
|
A bitmap consist of a header telling wich color depth it has how large it is and the data describing the image etc, etc. This is what is supposed to be sent to the printer coverted to ASCII characters. I'm not talking about ASCII art, and it is not "commands" which tells the printer what to do, it is just plain data that the printer interprets as an image.
At the moment I haven't got the actual printer model and hence no manual. I thougth that this was a common problem for which there are quite a few solutions to?!
|
|
|
|
|
Mats Eurén wrote: and it is not "commands" which tells the printer what to do, it is just plain data that the printer interprets as an image.
How do you think the printer knows what's an image and what isn't?? You have to format the data with the correct COMMAND CODES, which as specific to each printer, to tell it that the data that's coming is an image and how to render it. But, without the manual/documentation on the command codes the printer understands, you'll find it impossible to do this.
Mats Eurén wrote: I thougth that this was a common problem for which there are quite a few solutions to?!
No, actually, that is a very old method of getting the printer to print an image. Today, it's done through printer drivers that handle images automatically. You basically draw the image to a drawing surface that represents the page, then the printer driver converts that image into a stream of command codes and data that the printer understands.
|
|
|
|
|
Alright, I'll have to get more basic facts about the printer first then?! Thanks anyway.
|
|
|
|
|
I want to insert a table from a MySQL database with a DataGridView, but I have the common problem with IndexOutOfRange, if someone can help me with my code, to correct the errors. Sometime is working ok, sometime not.
private void bWorkGridView_DoWork(object sender, DoWorkEventArgs e)
{
initGridView();
MySqlCommand command = conexiuneSQL.CreateCommand();
command.CommandText = "select * from preluari";
mySqlDataAdapter1 = new MySqlDataAdapter(command);
DataSet ds = new DataSet();
mySqlDataAdapter1.Fill(mySqlDataTable1);
binding.DataSource = mySqlDataTable1;
if (GridView.InvokeRequired)
{
GridView.Invoke(new MethodInvoker(delegate { Thread.Sleep(200); GridView.DataSource = binding;}));
}
}
I'm working with BackgroundWorker to update the DataGridView and for connections I'm using dotconnect
|
|
|
|