|
I wasn't talking about the Graphics object passed to Paint(), I know it is not supposed to be cached and reused. I was talking about other Drawing related objects like Brushes.
[EDIT]My bad, it looks like I did say that for Graphics too, I didn't realise he was talking about the Graphics object specifically [/EDIT]
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Yeah, I wouldn't recommend holding onto any unmanaged handles for longer than the current paint event. Since there are limits to the number of handles (of any type) that can be checked out system-wide, its considered good practice to not hold onto them for any longer than you absolutely need to.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
But wouldn't the cost of acquiring the unmanaged resource (most probably through transitioning to unmanaged code) and releasing it warrant caching? And we are just caching a few handles, do you think that would make the system run out of handles?
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
The cost of allocating those resources is negligable. You're not gaining that much of a perfomance benefit by caching it. Also, if you cache the handle, then change the screen resolution or color depth, the handle is no longer valid for drawing.
No, just caching a few handles will not run the system out of resources. But it requires you to keep track of them for the duration of the application session. Just about everything in Windows has a handle attached to it, some even use thousands at a time. The performance benefit is just not worth the extra overhead of caching them.
Allocate it, use it, free it... Would you open a database connection and hang onto it for the duration of your app?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
I actually would. Prior to ADO.NET, we used to maintain our own database connection pool and the application ran significantly faster. Same concept as thread pools. But yeah, I do agree with your point though, it might not be worth caching those objects.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Even though it's expensive to open a database connection, it's considered extremely poor practice to open a connection and hang onto it for the duration of the app. Since SQL Server connection licenses are ($)expensive, and there are a limited number of them compared to the number of users using the system, it's always good form to create the connection and hold it open only for as long as absolutely necessary.
Remember, the number of SQL connections available are not specific to one application or database, they're available for the entire server! So, depending on the situation, it's entirely possible to support 10,000 users on 500 licensed connections, using many different database applications. Think about it...How many user would be using the system at any one time? How many of them are going to be accessing the databases at exactly the same time? What kind of money would your customer like to spend? It's always as little as possible, correct? So why would your customer spend the money on 10,000 licenses when only about 1,000 of them, max, are going to be using the system at any one time?
Starting to see how "Grab it, use it, release it" is considered "best practice"?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
|
Don't take my word for it! Start asking around about what is considered best practice for database connections.
It is true that ADO.NET does do connection pooling, but it does the very same thing that I've talked about. The connection to the server is closed, releasing the connection license on the server until ADO.NET decides it needs to be opened again.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hi to all,
can anyone point me in the direction of how to create a frontend (web-based) to record messages from a client and store them on a server(they log into) as mp3 or files ready for on-demand streaming through WMS?
tutes or links on audio recording / resampling ??
is this even possible using c#? eventually would also have functionality to dial into server (cell, landline) and record files that way ??
kind regards
g00fy
|
|
|
|
|
I have created a Windows service which compares the Current Date with one stored in the registry and if they are the same or the date stored in the registry is older than the current it launches an updater.
The updater is an exe i created too and it works perfectly using the ThreadPool class, but the main problem is the files it download could be images as they could be videos so the download may take a time. I have some buttons and properties in the updater but if its launched from the Windows Service , the updater runs in the background.
I know theres a property from the management service aplication( Allow interaction with desktop) but ¿ is there a property which allow u to do that from the main code, wen u install the service or so?
Dont like the idea of phoning my customers and tell em what to do or just drive for hours just to go there and make 2 clicks.
Ty for ur time.
|
|
|
|
|
Please help me,I want to extract the sql query from a report in C# and after I modify the sql, the report change after the new sql.
Thanks.
|
|
|
|
|
I need tobe able towrite to the registry in my app every time you run it, but on none-administrator accounts you do not have the permission write to parts of the registry,is there a way that i could get such permissions without logging on to an administrator account, or changing the accounts so that they can write to the registry?
thanksfor any help!
|
|
|
|
|
No, there isn't. And you can't just ask for and get the permissions needed either.
The accounts must either be given the permissions to write to those sections of the registry you need, (BTW, not a good idea!), by modifying the ACL's on the specified keys, or you change the users group rights to a higher level to allow greater unrestricted access (also a lousy idea).
Why must your users write to restricted portions of the registry?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
hi,
i am feeling a poblem. can anyone help me in blocking a packet on the network. so we check the paket and then route it if it is valid or drop it.
so the problem is to sniff snd blok packet.
Thanks.
|
|
|
|
|
You don't know much about network traffic, do you?
Sniffers only look at what's passing by, they don't intercept and block anything...
What your looking for is a router! Unless your machine is physically in the path of the network packets, meaning that ALL network traffic on that segment passes THROUGH your machine (not aorund or passes by it), there's nothing you can do to block anything.
BTW, this is already implemented in the form of Windows Routing and Remote Access...
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Is there something faster than .|[\r\n] in Regular Expressions ?
|
|
|
|
|
|
|
I want to match multiple-line comments from /* to */ so I use:
Regex regex = new Regex("/\\*(.|[\r\n])*?\\*/");
|
|
|
|
|
|
|
Hi there,
The following code generates the CS0122 "System.IO.FileStream.FileStream() is inancessible due to its protection level."
What am I doing wrong?
Thanks,
Akos
>>>>>>>>>>
The code:
using System;
using System.IO;
namespace MyStreamReader
{
///
/// Summary description for MyStreamReader.
///
public class MyStreamReader : System.IO.FileStream
{
public MyStreamReader()
{
//
// TODO: Add constructor logic here
//
}
}
}
|
|
|
|
|
the mistake in your code is that you are trying to use the default contructor of the filestream class. But this constructor isn't accessible. A solution to this problem is just using another constructor of the filestream class. You can call other constructors via the base synonym(as you can see in the following code).
class b : System.IO.FileStream
{
public b(string str): base(str,FileMode.OpenOrCreate)
{
}
}
|
|
|
|
|
Beauty! Thanks Hooray!
Akos
|
|
|
|
|
when i use the method Mesh.clean(...), throw a exception of System.NullReferenceException. this is my code:
private void LoadMesh(string file)
{
ExtendedMaterial[] mtrl;
GraphicsStream adj=null;
// Load our mesh
mesh = Mesh.FromFile(file, MeshFlags.Managed, device, out adj, out mtrl);
// If we have any materials, store them
if ((mtrl != null) && (mtrl.Length > 0))
{
meshMaterials = new Material[mtrl.Length];
meshTextures = new Texture[mtrl.Length];
// Store each material and texture
for (int i = 0; i < mtrl.Length; i++)
{
meshMaterials[i] = mtrl[i].Material3D;
if ((mtrl[i].TextureFilename != null) && (mtrl[i].TextureFilename != string.Empty))
{
// We have a texture, try to load it
meshTextures[i] = TextureLoader.FromFile(device, @"..\..\" + mtrl[i].TextureFilename);
}
}
}
// Clean our main mesh
Mesh tempMesh = Mesh.Clean(CleanType.Simplification ,mesh, adj, adj );
// Replace our existing mesh with this one
mesh.Dispose();
mesh = tempMesh; //when run here, throw a exception
}
i have no idea that what can i do.
|
|
|
|
|