|
Hello all,
I've noticed an "interesting" behavior in winforms. If I have a custom control whose paint event is overridden to draw a gradient background. When the control is docked and I try to create a LinearGradientBrush by specifying colors and a rectangle, I get an Out of Memory exception. OutOfMemoryException is the most useless exception type, because it does not allow you to fix or even diagnose problems in your code. You are simply screwed as far as I can tell.
Does anybody have an idea why this happens when the control is docked, but does not occur at any other time (like when the control is anchored to achieve the same effect)?
Will
|
|
|
|
|
I guess you should verify the dimensions of your rectangle in either case...
Regards,
mav
|
|
|
|
|
|
That's possible. I didn't unit test that code as thoroughly as I should have. I was thinking it was something like running out of a handle, which didn't make sense at all. I'll have to check that when I get home tonight.
That still doesn't explain what would cause the problem to occur only when the control is docked. Any ideas?
Will
|
|
|
|
|
From personal experience, exhausting the handle pool will generate OutOfMemory exceptions. This can easily happen if you grab a Graphics object and don't Dispose it.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Does this mean I should worry about re-entering the paint method of my form? In other words, can it be called from multiple threads (I would think not, since the message loop is single threaded)?
So far, I've been having problems on the first attempt at painting, so I doubt that I am overallocating GDI objects. I also use the using statement religiously. I am creating a graphics object in the background however, to enable double-buffering - I'll check that as well.
Will
|
|
|
|
|
gantww wrote:
Does this mean I should worry about re-entering the paint method of my form?
If, by this, you mean that your Paint method is calling itself, you've got huge issues. Paint should never call itself recursively.
gantww wrote:
In other words, can it be called from multiple threads (I would think not, since the message loop is single threaded)?
You should NOT be doing this. You can invoke an Invalidate call back on the UI thread, but you should NEVER make a direct call from a thread to a forms Paint code. Bad, and unpredictable, things will happen.
gantww wrote:
I am creating a graphics object in the background however, to enable double-buffering -
You're what? Are you saying that you're creating a Graphics object on a background thread? Bad idea! Graphics objects should only be created on the thread that created the control your painting.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Uhh. I was running real low on caffeine when I wrote the above statements. Let me rephrase them. I'm creating a graphics object in paint and drawing to a bitmap first (in many cases, anyway) and then painting that bitmap onto the form using the graphics object provided by the event handler. I'm not invoking the paint event from multiple threads or recursing it - I'm wondering if there is any way that windows (or the development environment) could be doing something like that behind my back. I'm particularly concerned that it may be occurring while I'm debugging the code (I'm using dual monitors, so I don't have all the problems of debugging paint code).
By the way, I checked my code and I was able to reproduce the issue where a colorblend was not ending with 1.0. My calculations were off very slightly. I'm hoping that will fix the issue.
Thanks,
Will
|
|
|
|
|
gantww wrote:
I'm wondering if there is any way that windows (or the development environment) could be doing something like that behind my back.
No chance.
gantww wrote:
By the way, I checked my code and I was able to reproduce the issue where a colorblend was not ending with 1.0. My calculations were off very slightly. I'm hoping that will fix the issue.
More than likely.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
i want someone help me in this small part of my project
i have client / server App ;
in client there is a login form that send username and password to server
that server chek these in its DB and if true it ((CREAT OBJECT )) called user and send this object to the client machine
i ask about the most effcient tecniuqe is it Remoting or web service ? if it web service i don't want use internet i mean it must be locally
i want help please
|
|
|
|
|
|
Web Service does not mean that you HAVE to go over the internet.
Just have it running on your service and use the machine name on the client. Your network config should then auto-magically decide that no outside routing is necessary.
Cheers,
Sebastian
--
Contra vim mortem non est medicamen in hortem.
|
|
|
|
|
If you can see your server application being consumed by non .NET clients on the same machine then web services are the only way to go.
Otherwise, I don't see what's wrong with remoting.
See this article, it might help you out: http://www.developer.com/net/net/article.php/2201701
|
|
|
|
|
I hope you really meant to say that you send the username and a hash of the password to the server and check whether they are in the database.
Matt Gerrans
|
|
|
|
|
Hi everybody,
I am working on a PDA project and the user interface (UI) should be constructed by reading XML files (XMLTextReader) and upon the contents creating the approperate Contols.
The problem is on the following areas:
1. How to adapt the perant-child relationships between controls obtained from XML file and set them(since .net Compact Framework does not support Name property in Control class)
2. Connecting event handlers is not a problem but how to access within the event handler another controls (not the sender) which will be created in runtime.
Every reply is welcomed!
Thanks in advance for the effort.
tutah
|
|
|
|
|
How to add controls to OpenDialog box?
|
|
|
|
|
Is this what you are looking for?
this.regsiterStartupScript("tjoff", "window.open('url', '_blank');")
/M
|
|
|
|
|
I'm sorry that i didnt mention it earlier, but i need to add combobox to opendialog box in winForms.
|
|
|
|
|
Hi all,
I'm going to verify a selected item of a combobox with the contents of a datatable in the
combobox.SelectionChangeCommitted method.
But
"SELECT * FROM table WHERE field = " + combobox.Text;
fails due to the combobox.Text doesn't got the selected item yet.
When does the combobox.Text has the valid value from the selected combobox.list ?
Is there a flag to check for completing
I don't want to use a delay or wait.
Thank's for your ideas
Frank
|
|
|
|
|
Use SelectedValue instead of Text.
---
b { font-weight: normal; }
|
|
|
|
|
How to pass arguments to the thread...
I do the next things in the constructor:
m_PaintThread = new Thread(new ThreadStart(PaintMap));
And next things in function that calls the thread:
if(m_PaintThread.IsAlive)
{
m_PaintThread.Abort();
m_PaintThread.Join();
}
m_PaintThread.Start();
So...
In that thread i draw the map, and i call the function CreateGraphics,
but it says that an object reference is required when i call nonstatic method...
I remember in C++ I could pass the parent class in parameter LPVOID lParam,
But how to make it here???
And another question - How to paint map Without Flicking? So how to implement double buffered painting...
|
|
|
|
|
Use ThreadPool.QueueUserWorkItem(), which lets you pass a single object argument to your thread. Or use TheDelegateYouAreUsing.BeginInvoke, which allows you to pass all the arguments necessary.
Rassul Yunussov wrote:
How to paint map Without Flicking? So how to implement double buffered painting...
Inherit a new class from the control you want to draw on. In its constructor, use this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint, true);
A word of warning: be careful passing state between threads. It's generally a bad idea because things get hairy when dealing with multiple threads accessing the same variable.
Also, keep in mind you should NEVER access a Windows Form control (or any other Win32 common control-based object) from a thread other than the creating thread. The only Windows Forms control methods you're allowed to call on another thread are Invoke, BeginInvoke, and CreateGraphics().
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Conversation With a Muslim
Judah Himango
|
|
|
|
|
But how to Stop the thread, created by this method???
It is necessery to stop my thread, because it draws the image in the canvas and if i'll start to draw the scene, when the first thread haven't finished its work they both will draw??? The image will be spoiled... I think...
|
|
|
|
|
The thread will stop when the method has finished executing. If you want to cancel it before then, either roll your own cancelling mechanism (have some static "cancelled" flag or something), or use Thread.Abort() and catch the resulting ThreadAbortException.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Conversation With a Muslim
Judah Himango
|
|
|
|
|
Hi,
I'm new to C# and .NET framework.
I need to send several files to a AXIS (Java) web service. This web service takes as Input an HashMap that has the files mentioned. The complex type HashMap has been serialized with success and I'm able to send this type to the service:
eg. :
namespacexpto.mapItem [] mI = new namespacexpto.mapItem[2] ;<br />
mI[0] = new namespacexpto.InsDoc.mapItem();<br />
mI[0].key = "key";<br />
mI[0].value = value;
Serialization:
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://xml.apache.org/xml-soap")]<br />
public class mapItem {<br />
<br />
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]<br />
public object key;<br />
<br />
[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)]<br />
public object [] value;<br />
}
My question is how can I send (if possible) the files to the Web Service. If that is not possible, can anyone suggest a different approach to the problem.
The Java source that implements the service is:
(...)<br />
File ficheiro = new File(filepath);<br />
FileOutputStream fout = new FileOutputStream(ficheiro);<br />
<br />
AttachmentPart teste =(AttachmentPart) map.get("ficheiro");<br />
<br />
DataHandler dj = (DataHandler)teste.getDataHandler();<br />
<br />
BufferedInputStream in = new BufferedInputStream(dj.getInputStream());<br />
while(in.available()!=0)<br />
{<br />
fout.write(in.read());<br />
}<br />
System.out.println("ficheiro is file " +ficheiro.isFile());<br />
while (ficheiro.length() == 0)<br />
{<br />
<br />
}<br />
fout.flush();<br />
fout.close();<br />
(...)
Tanks in advance for all the help.
|
|
|
|