|
Many thanks for the advice.
|
|
|
|
|
I have a custom control that draws text and images. The images are drawn for each item from a single ImageList:
MyControl control = new MyControl();
control.ImageList = this.imageList1;
In the drawing code, I have something like this:
protected override OnPaint(PaintEventArgs pe)
{
pe.Graphics.DrawImage(this.ImageList.Images[0]);
...
}
This is butt-slow! The paint event seriously slows down the entire app everytime I draw. Running it through a profiler tells me accessing the image out of the image list is the culprit (?). And indeed it is; if I store a reference to the image to draw (instead of getting the image out of the image list), it's super fast:
private Image imageToDraw = null;
public MyControl()
{
imageToDraw = this.ImageList[0];
}
protected override OnPaint(PaintEventArgs pe)
{
pe.Graphics.DrawImage(this.imageToDraw);
...
}
Can anyone tell me why this is the case? The only difference between the two code snippets is that the first calls DrawImage(imageList.Images[0]) and the second snippet calls DrawImage(someImage). Is retrieving the image out of an image list really that slow?
#include "witty_sig.h"
|
|
|
|
|
If you're intersted in the internal workings of classes, use the IL disassembler (ildasm.exe) that ships with the .NET Framework SDK or use a decent decompiler if you don't know IL like .NET Reflector[^].
The ImageList class uses the Image list common control, so it encapsulates said control by sending Windows messages (using the macros, actually), which requires marshaling to/from unmanaged code.
A faster way, however, is to use ImageList.Draw . This uses the HDC of the Graphics for your painting operation - as well as the other parameters - to have the image list common control draw the image directly to the on- or off-screen bitmap (depending on whether or not you're using double-buffering), or to the Image you're trying to draw (obviously not the case here). This will definitely be faster than your first method and would provide the robustness you may be looking for (like if the images in the list change often and you just want to always draw the first one, or some other index), as opposed to coming up with some caching schema and implementing it using your latter approach.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Yes I heavily use ildasm here at work, nice little bugger.
Yup I am aware that marshalling is going on...I just didn't think it would really be *that* much slower. Pretty amazing. I'll give ImageList.Draw a try, see how fast that is relative to my other 2 options.
Thanks Heath for the lightning fast reply. Helpful as always.
#include "witty_sig.h"
|
|
|
|
|
I just ran some tests using ImageList.Draw - works brilliantly.
Thanks again!
#include "witty_sig.h"
|
|
|
|
|
Judah Himango wrote:
I just ran some tests using ImageList.Draw - works brilliantly.
I'll keep that in mind
|
|
|
|
|
I wish to jump from running the main form Form1 to run my Form2. I want my Form2 to dispose Form1 and continue to run as the main form. I have excperienced som difficulty in doing this as when Form1 is disposed it will close Form2 even if i have set the reference in Form1 to acces Form2 to be null. I believe its because Form1 is running the main thread, is it possible for me to create a similar thread in Form2 to overtake the main thread.
|
|
|
|
|
Form1 is what the message pump is using to keep the loop alive so that it translates and dispatches messages throughout your application (Windows Forms just encapsulates Windows messaging and common controls). Disposing your form (or even closing it) stops the message pump.
If you're desiging a wizard-like interface, you should consider having a single form that maintains state between forms as well as navigation between them. And instead of Form derivatives, you could actually use any container control such as a UserControl (easiest to design in VS.NET, if you like that sort of thing).
There are several articles here on CodeProject that discuss this.
If you want to create a new main window for your application, then you could try using Application.Run on your instance of Form2 then dispose Form1 . I'm not sure how this would affect your application, however, since a new STA thread would be created for the new main window. Give it a try, though.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I'm trying to send .asf (audio stream) using a Client and a webserver, both in C#. When I try to submit data I get this exception:
"The request failed with HTTP status 413: Request Entity Too Large."
The file I'm trying to send is about 3-5 Mb.
Client:
<br />
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);<br />
BinaryReader br = new BinaryReader(fs);<br />
byte[] fileRD = br.ReadBytes((int)fs.Length);<br />
fs.Close();<br />
br.Close();<br />
wrGravadorWS.GravadorPA wsGravadorPA = new wrGravadorWS.GravadorPA();<br />
ret = wsGravadorPA.Save(fileRD); <br />
Webservice:
<br />
[WebMethod]<br />
public string Save(byte[] gravacao) <br />
{<br />
......<br />
}<br />
The code works fine when working with small files.
I use IIS 5.0. On MSDN there's no information about IIS 5.0, just IIS 6.0. I have made MANY researchs about this and I couldn't find solution.
This is all I have:
413-Request Entity Is Too Large
For security reasons, you can limit the size of the entity-body of an HTTP request by modifying the MaxRequestEntityAllowed metabase property. When an entity-body of a client request exceeds the size that is specified in the MaxRequestEntityAllowed property, IIS returns a 413 error. If this error is logged for an individual request, an application on the Web server might have encountered an unexpected event and generated a request that is too large. If this error is logged for many requests, a malicious user might be attempting to compromise your Web server.
Where I cant make this change on iis 5? (the IIS 6 metabase is a xml file). On registry, it doesn't make any diference.
Thank you!!
Edgar
|
|
|
|
|
There are some windows scripts to change the metabase in IIS 5, but ASP.NET is most likely what's returning the error here since it maintains it's own execution environment and has a setting for maximum request sizes. Open your machine.config file for the version of ASP.NET your site is running in and change the maxRequestLength in the <httpRuntime> element.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I forgot to say that I tried this before. Without this change (I placed in web.config and machine.config) there is a security error. After this change (maxRequestLength at httpRuntime element) I receive a 413 error from IIS 5
Thank you!
Edgar
|
|
|
|
|
IIRc, the web.config cannot contain the <httpRuntime> element, which is probably why you got the security error. Since you didn't state what the exception type and message was, though, it's difficult to say for sure.
Your problem is a common problem, and the fix I recommended is the common solution, even on Microsoft's KB. If you still believe it's IIS, go to http://support.microsoft.com[^] and look for max request problems. The scripts to modify the metabase should be mentioned, as well as the params to specify.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thank you again for your help. I will try to use DIME instead. Changing machine.config didn't worked.
|
|
|
|
|
|
I am translating some code from VB to C# all was going swimmingly until I hit these lines :
Const SC_MP = &HF170&
Public Const M_ON = -1&
Public Const M_OFF = 2&
Const WM_SYSCOMMAND = &H112
Now I assume that these are int declarations but what format are they in and how can I translate them to standard hex/number representations
|
|
|
|
|
They're hexidecimal, or base 16 numbers (at least the first and last ones). In C# they'd look like this:
const int SC_MP = 0x0170;
public const int M_ON = -1;
public const int M_OFF = -2;
const WM_SYSCOMMAND = 0x0112;
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hai there,
i got little bit information about Borland C# Builder. give me some detailed information about this. And Recomanded books or CDs
hai, enjoy coding
Sreejith SS Nair
|
|
|
|
|
sreejith ss nair wrote:
give me some detailed information about this.
Ever heard the word "please"? You often demand things from others on this site. There's not a languages I've heard of that doesn't have a word similar to "please".
If you want information about Borland's C# Builder, the logical place is their web site[^]. There's plenty of whitepapers to download.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
How to compare two files,like "Microsoft Visual SourceSafe"!
Code by C#!
I am English is poor!
thank you!
|
|
|
|
|
Comparing files isn't something for beginners. Start basic. If you don't already know the types of pattern matching algorithms for comparing text files, then do it the easy way. Redirect the output from a new Process you can create using the FC command or various console-based diff tools out there, like that in cygwin[^] ('diff').
A .NET console application that wraps the FC command (it's not an application, but an interpreted command in the command shell) would look like this:
using System;
using System.Diagnostics;
public class Diff
{
static void Main(string[] args)
{
if (args.Length != 2)
{
Console.Error.WriteLine("You must provide two filenames.");
Environment.Exit(1);
}
string cmd = "cmd.exe";
if (Environment.OSVersion.Platform == PlatformID.Win32Windows)
cmd = "command.exe";
Process p = new Process();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = cmd;
p.StartInfo.Arguments = string.Format(
@"/c fc ""{0}"" ""{1}""", args[0], args[1]);
p.Start();
p.WaitForExit();
string line = p.StandardOutput.ReadLine();
while (line != null)
{
Console.WriteLine(line);
line = p.StandardOutput.ReadLine();
}
}
} If you're interested in actual text diff'ing, there are projects on SourceForge[^] where you can browse the source, as well as otherplaces with open source code for utilities like diff. It's not something easy to cover in a forum.
Some books on programming algorithms will have this information as well.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i want to invoke some functions in API dlls or other 3rd part dlls.
and i learn to use [dllimport]declaration to invoke them.
but there are still some problems:
how to invoke such function with pointer param as this:
C++Function( byte* b ){} ?
i dont know how to convert pointer type to c# type.
and also this function in GDI32.dll:
int GetDIBits(
HDC hdc, // handle to DC
HBITMAP hbmp, // handle to bitmap
UINT uStartScan, // first scan line to set
UINT cScanLines, // number of scan lines to copy
LPVOID lpvBits, // array for bitmap bits
LPBITMAPINFO lpbi, // bitmap data buffer
UINT uUsage // RGB or palette index
);
how to declare the LPVoid type(it should be a pointer) ?
|
|
|
|
|
From www.pinvoke.net [^]:
[DllImport("gdi32.dll")]
static extern int GetDIBits(IntPtr hdc, IntPtr hbmp, uint uStartScan,
uint cScanLines, [Out] byte [] lpvBits, ref BITMAPINFO lpbmi, uint uUsage);
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
Oh , and for ppointer I think you have to use IntPtr .
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
A pointer can always be declared as an IntPtr , but often times you really have to know the difference between value types and reference types. For a reference type, if you see an unmanaged declaration like ISomeInterface* , then you should (after declaring a managed interface named ISomeInterface just declare it as ISomeInterface . Interfaces are always reference types (a managed pointer) so the address is already passed. If you need to pass an array (like byte* or byte[] , then just pass the array byte[] . An array is also a reference type, regardless of the element type. If you need to pass a reference to a struct (declared as SOMESTRUCT* in unmanaged code), then use either the out (for [out] declarations) or ref (for [in,out] declarations).
Also, while not required (in most cases) you should use the InAttribute and OutAttribute</copde> for parameters documented as [in] and [out], respectively. Many times you will also need to use the <code>MarshalAsAttribute to help the CLR determine how to marshal parameters across managed boundaries. See the documentation for those three aforementioned attributes in the .NET Framework SDK for more information.
There's also a topic in the .NET Framework SDK you should read, Platform Invoke Data Types[^], which have the type-maps for common unmanaged and managed types (like a common mistake is thinking a LONG in C/C++ is a long (Int64 ) in .NET; it's not - it's a 32-bit integer and hence an int (Int32 ).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thanks for your discussion.
i can learn many from it!!!
|
|
|
|