|
Actually, it doesn't dump out of the loop if there's a space, it just doesn't append it to the output string. The while loop will continue to process until EOF is reached on the file. If you wanted it to stop the loop if an emptry string were to occur, you would need to add a break; statement in there.
-- modified at 19:02 Thursday 23rd August, 2007
BTW, I am zerosity, just had to change the username for the forums as I never did that when I registered way back in time.
|
|
|
|
|
Hi all!
First I would like to say, if it wasn't for the codeproject at all, I would't know C#. My question is the following, i've been trying to figure it out forever!
I have an application, which launches a thread, there is a keyboard hook present in the thread, when the thread receives a keypress, and it matches the criteria, the thread launches another thread and aborts. The problem with this is that the memory that the thread used is not cleaned, is there a way to dispose a thread or something, completely free up all memory it used? because the problem is that after a few keycombinations, there is a huge memory load that is totally worthless, i read somewhere about appdomains, but couldn't get them to work.
Can somebody help?
Kind Regards,
Nick Verlinden
Nick Verlinden
c#-Lover
|
|
|
|
|
verlinden.nick@telenet.be wrote: The problem with this is that the memory that the thread used is not cleaned
First of all, are you sure about this? What are you using to measure memory usage? If it's just the Task Manager, chances are you're not looking at the right data. Use a memory profiler, such as the free CLR Profiler or the commercial ANTS profiler.
Now, if you're certain memory keeps building, that means something is keeping your thread alive. Something with a reference to that thread, perhaps? The only way to tell is look at the live objects -- again you'll need a profiler for this -- and see what's still alive that doesn't need to be.
Another possibility is, the .NET garbage collector simply hasn't run and cleaned up the memory used by the thread. You can force a garbage collection just to test this theory: call GC.Collect() to force one.
A final note: it's preferred to use the .NET thread pool instead of creating threads yourself. This way, existing threads are reused instead of being created over an over again. You can use the thread pool using the System.Threading.ThreadPool class.
|
|
|
|
|
Just to add some more information.
I'm not sure what you're doing with these threads, but if it's executing unmanaged code while you abort the thread, the thread will not abort until the unmanaged code has completed. A ThreadAbortException will be raised during any attempt during an abort.
|
|
|
|
|
Yes, unmanaged code is running, hook to keyboard, but normally, the hooks should be ended before aborting. I tried several programming methods, but this is the only one working for me. I'm talking about a thread launching another thread and killing itself. This is because the threads are on different desktops.
Thanks for the reply,
Kind Regards,
Nick Verlinden
|
|
|
|
|
Dag Nick,
I have several comments/questions:
1.
It seldom is a good idea to abort a thread; you typically don't know what state it is
in, what resources it may be holding, etc, so you may cause deadlocks and memory
leaks. The preferred way is to have the thread cooperate on its own termination by
regularly checking some flag, or something like that.
2.
I don't see the logic in creating a new thread and aborting another one at the same
time. It you find a way around this, I expect your code will be simpler and not have
the (presumed) memory problem at all.
3.
I am not sure I understand your "when the thread receives a keypress": GUI events
get handled by the GUI thread, normally that is the main or initial thread.
So how can another thread get hold of those KeyPress events ?
In summary, you may have to rework the threading situation; if more help is
wanted I would suggest you provide a more detailed description (+ some code) of your
set-up.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi Luc,
Thanks for the reply. To answer a few of your questions, i tried several programming techniques, but this is the only way I can get it done, after a month of trial and error. The means why i program it that way, meaning the thread launching another thread and aborting itself, is becasue the threads run on different desktops. I also need global keyboard hooks, but they should be unhooked before the thread receives an abort.
Kind regards,
Nick verlinden
|
|
|
|
|
Hi Nick,
we are missing a lot of context here.
seems you have two desktops (meaning two PCs I guess), some threading problems,
and something that starts to work after one month of trial&error, but not quite.
you must explain it all (in a top-down description) if you want anything helpful,
and probably provide several code snippets too.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi Luc!
I'm trying not to give too much information away , but i know that i will have too, so here it goes. I have multiple desktops "desktops as in windows desktops, not computers, for example winlogon is also a desktop (winlogon is the desktop where the alt+CTRL+DELETE window is shown)" when the user presses a key on the keyboard, it switches to antoher desktop. But since the keyboard hook is only valid in the desktop where it is being launched, so i have to abort the thread in the previous desktop and launch a new thread in the new desktop, else the user can't switch back to the previous one. if the user switches back to the previous one, the routine repeats. the problem is that the thread that was listening on the previous desktop does not release its used memore, well that's what i think at least. It has unmanaged code for the keyboard hooks.
Is that helpfull?
Kind Regards,
Nick Verlinden
|
|
|
|
|
Hi Nick,
With so little information I can't help you effectively.
I don't understand how a keyboard hook would imply a thread, a hook lets you attach
your code to some event, the event itself provides the thread, you should not care
about that.
And as I said before I object to aborting a thread.
You probably want to neutralize an existing hook temporarily; you could do that
by having some flags that get tested in the hooked procedure. Or you may choose
to remove the hook (e.g. when a "desktop" deactivates), that would require
an event to call the right system function, no abort involved !
That is all.
Luc Pattyn [Forum Guidelines] [My Articles]
this weeks tips:
- make Visual display line numbers: Tools/Options/TextEditor/...
- show exceptions with ToString() to see all information
- before you ask a question here, search CodeProject, then Google
|
|
|
|
|
Hi Luc!
Thank you for your reply, I will try to revise my code a bit, but it's gonna take a while. Thank you for your help Luc! Maybe i'll get the chance to help you some day, who knows!
Kind Regards,
Nick Verlinden
|
|
|
|
|
Hello,
I have to show a ContextMenuStrip in the Header of the DataGridView.
In the event
ColumnHeaderMouseClick do datagridview i catch the coordenates e.X and e.Y of the mouse, but the ContextMenu doesn't appear where the mouse is, i always
appears in the first columns.
look the image
thank you a lot
|
|
|
|
|
The e.X and e.Y coordinates are probably local. Convert them to screen coordinates before showing the context menu:
Point localPoint = new Point(e.X, e.Y);
Point screenPoint = dataGridView.PointToScreen(localPoint);
myContextMenu.Show(screenPoint...);
|
|
|
|
|
Please provide me code that converts PDF into JPEG without using any third part dlls.Thanks in Advance...
adil kazmi
|
|
|
|
|
Tell us first what you did to find a solution to this problem. (hint : Google)
|
|
|
|
|
I tried in Google but didn't get the required solution.
adil kazmi
|
|
|
|
|
adilkazmi wrote: without using any third part dlls
Good luck with that! You won't find one. And noone is going to write the code for you.
|
|
|
|
|
hey..Mind your bluddy language..I am not saying you to write the code.
just do your work...
don't give pain to your knee..[;(]
adil kazmi
|
|
|
|
|
adilkazmi wrote: hey..Mind your bluddy language
It would appear to me that you are the one using profanity (badly spelled profanity at that)
adilkazmi wrote: I am not saying you to write the code
True, you said "provide me code". But "provide" implies that the person you asked must do the work to create the code, or do the work to find the code. Either which way, you are asking others to do your work. Perhaps if you had phrased your question in a less provokative way you would get a better response. e.g. "Help me find the code" that implies to are trying to do the work but need assistance. We like to help people. We especially like to help people that show that they are trying to help themselves.
adilkazmi wrote: don't give pain to your knee
I can only imagine that is some idiomatic expression literally, rather than figuratively, translated.
-- Always write code as if the maintenance programmer were an axe murderer who knows where you live.
Upcoming FREE developer events:
* Glasgow: Agile in the Enterprise Vs. ISVs, Mock Objects, SQL Server CLR Integration, Reporting Services, db4o ...
* Reading: SQL Bits
My website
|
|
|
|
|
You should know by now that when you post to these forums, the people who want to help you are volunteers and have no obligation to answer your questions or write your code. This subject matter of converting pdf to image is primarily undocumented and is left to expensive third party controls to solve the problem and you will just have to live with it.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
Hello,
I have a data grid view, and what I am trying to do is, grab all the column headers and put them into a combo box or list box.
what I have so far is:
foreach (DataColumn column in this.dataGridView1.Columns)
{
this.listBox1.Items.Add(column.ToString());
}
I get an error with this, it is:
"Unable to cast object of type 'System.Windows.Forms.DataGridViewTextBoxColumn' to type 'System.Data.DataColumn'"
Any help would be apreciated.
Thanks
J
|
|
|
|
|
you can try:
foreach (DataColumn column in this.dataGridView1.Columns)
{
this.listBox1.Items.Add(column.HeaderText);
}
|
|
|
|
|
|
Thanks... The end result that I ended up with is:
foreach (DataGridViewColumn column in this.dataGridView1.Columns)
{
this.listBox1.Items.Add(column.HeaderText);
}
|
|
|
|
|
this.dataGridView1.Columns returns a collection of GridViewColumn, not DataColumn. In this case, the column returned is a specialized version of GridViewColumn which contains a textbox.
<br />
foreach (GridViewColumn in this.dataGridView1.Columns)<br />
{<br />
this.listBox1.Items.Add(column.HeaderText);<br />
}<br />
|
|
|
|
|