|
Okay, I'm not trying to sound stupid, but is there some reason you shouldn't just use an instance of something like Hashtable or StringDictionary directly? I mean, is there something specific you need out of your new class that isn't supported by the built-in collections?
It sounds like you're not going to be modifying the structure during the life of your application. If so, don't make it synchronized, as this will impair performance a little. But if you will be modifying the data, you should synchronize it. With Hashtable, this can be done very easily:
Hashtable hashtable = Hashtable.Synchronized(new Hashtable());
One more tip: if your hashtable will be read very frequently, you should leave a lot of empty space in it, to minimize the chance of an index collision. You can do this by setting the load factor, or by choosing an initial size that's much bigger (say, double or more) than
the number of expected entries. This should be a really miniscule memory whack, since your object will be shared by the whole application.
You might want to also play around with ADO.NET's caching features. One of the coolest features of .NET is the ability to basically keep an in-memory database, searchable and all. I don't think your problem calls for this, though.
Regards,
Jeff Varszegi
|
|
|
|
|
hi,
I have a question about changing a text(string) to an image(.jpg) in a web page.
I have the code below but when I use it other web controls doesn't initialize??
I mean if I put some text boxes on the .aspx page it doesn't show them only show the .jpg and if I use the code not in page_load it doesn't work,strange isn't it? How can I solve this?
Code:
using System.Drawing;
using System.Drawing.Imaging;
private void Page_Load(object sender, System.EventArgs e)
{
Bitmap b = new Bitmap(250,80);
Graphics g = Graphics.FromImage(b);
SolidBrush sb = new SolidBrush(Color.Green);
Font f = new Font("Arial",12);
g.FillRectangle(new SolidBrush(Color.White),0,0,250,80);
g.DrawString("This is a cool thing",f,sb,5,10);
Response.ContentType = "image/jpeg";
b.Save(Response.OutputStream, ImageFormat.Jpeg);
g.Dispose();
b.Dispose();
}
how can I solve this?
Best wishes,
-
When in doubt, push a pawn!
-
|
|
|
|
|
Of course it doesn't work, you're outputing the image to the page response stream itself! What you need to do instead is to have this in a separate page and the first page references that in an IMG tag, along with possible parameters (as a query string) to control what text is output (and/or size, etc.). You've got the right idea, but you need to remember that the page and the files (images, scripts, stylesheets) are all separate references to different files. You can't combine them (generally speaking, not without MIME at least).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks!it worked
-
When in doubt, push a pawn!
-
|
|
|
|
|
Hi.
Is it possible to catch system events such as SessionEnding in a windows service? I tried to hook on a method to the event, like Microsoft.Win32.SystemEvents.SessionEnding +=new Microsoft.Win32.SessionEndingEventHandler(this.OnSessionEnding);
in the OnStart() method but now the service won't start. Is the problem that the service can not catch systemevents at all or have I done something wrong?
Thanks
/EnkelIk
|
|
|
|
|
hi
I guess you need to write an event handler function and event handler delegate. see if the following link can be of any help:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfmicrosoftwin32sessionendedeventhandlerclasstopic.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconeventsdelegates.asp
all the best.
ankita
|
|
|
|
|
Hiya all.
I'm trying to build a simple little client/server model application.
So far I have managed to get it to work with MarshalByRefObject but I really want to (need ) to make it so that it becomes a MarshalByValue.
I need the client to recive the neasecary object(s), instead of having a referece to the servers copy of the object.
Is there anybody that have/know of some code samples that can help me out.
(note I've only programmed in C# in about a week, so be gentle )
Thanks in advance.
<insert signature="" here="">
|
|
|
|
|
You have to add an attribute to the class so it becomes Serializable, e.g.
[Serializable] class something<br />
{<br />
<br />
}
Free your mind...
|
|
|
|
|
Yes, that much I have tried.
But how to get the object sendt from the server to the client, is what I can't seem to work out.
That is why I'm looking for a code sample of a client/server wich sends the object by value instead of by reference (wich I can get to work).
I've not been able to find any documents on the internet. Except for one, vaugely descriping it in VB.NET, wich I couldn't use, because my experience with VB is limited (limited to using it for server side scripting with asp).
But I would belive that somebody has to have made something similar (a "by-value" instead of "by reference" client/server), or knows about it.
<insert signature="" here="">
|
|
|
|
|
The [Serializable] Attribute makes an object pass by-value instead of by reference.
I built a client-server application and it worked fine.
Free your mind...
|
|
|
|
|
Hello,
I'm looking to find an elegant solution to the following problem.
I have a solution with various web.config and app.config files in it. The whole solution is version controlled with Microsoft Source Safe 6.0.
As I am developing on my machine, and running the software on my machine the various app & web .config files are set up to correspond with the view from my machine. However since this all gets put in source safe, if someone else gets the code and compiles and runs it loads of things stop working properly because the config files are all set up wrong. The same goes for any test deployments on to the main server. Each time the app gets moved each config file has to be revisited and altered.
I want to have something that will mean I can code and test quickly without having to alter the config files for my app/web projects each run, or have to copy files (which is what we're doing on the server).
Is there any way to do this seamlessly? Or at least quickly and efficiently.
Thanks,
Colin.
--Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)
|
|
|
|
|
We had the same problem and the way we addressed it was by creating config files for each known machine that we were going to deploy to. So in the project there is app.config, app.config.machine1 etc. When moving the application to the known machines we simply rename app.config.machine to app.config. Definitely not the most elegant way, but since we have known machines to which we deploy its not too much of a pain.
Alternatively, depending on the nature of data in the config file, you could write into your deployment application something that will alter your config files, by either prompting the user for information or getting the information from the machine.
|
|
|
|
|
I have a ListView with 7 columns viewed in details mode. I have a context menu tied into the ListView so the user can right click on one of the ListView items and perform certain tasks.
The problem is that I cant seem to get the values out of the ListView (with the exception of the value in column 1. From playing around in debug mode I have discovered that the values I want are actually held here :
myListView.SelectedItems.SelectedItemArray[0].subItems[n].Text;
Where n is the index of the column
The problem is this :
'System.Windows.Forms.ListView.SelectedListViewItemCollection.SelectedItemArray' is inaccessible due to its protection level
So how do I get to the values??
post.mode = signature;
SELECT everything FROM everywhere WHERE something = something_else;
> 1 Row Returned
> 42
|
|
|
|
|
I think you actually wanted
myListView.SelectedItems[0].SubItems[n].Text; At least, based on my reading of the documentation.
However, you might be better off associating a Tag with each ListViewItem , and operating on that object instead.
|
|
|
|
|
I do this all the time...
What you actually need to reference is...
myListView.SelectedItems[0].SubItems[n].Text
Darryl Borden
Principal IT Analyst
darryl.borden@elpaso.com
|
|
|
|
|
Hi all
I am a newbie where programming with c# is concerned. One thing that seems to come up often when reading about it and .Net is that you can use different languages on a piece of code. Is that possible and how do you do it. I have written a simple application which has a page that has buttons (navigate with them). I also have a clock in the corner, but I would love to use <%@ Page Language ="VB" %> together with c#. This means that the language used in buttons is c# but the language used in the clock is VB. all of this in one page, one piece of code, is it possible?
Thanks in advance
Zee
|
|
|
|
|
In ASP.NET, this is easy. Use the syntax below, which is basically legacy supported from ASP:
<script runat="server" language="C#">
</script>
<script runat="server" language="VB">
'...
</script> With assemblies themselves, you actually have to compile modules in different languages, and then link them together into the same assembly (which includes a manifest of assembly attributes, dependency references, modules, and embedded resources).
There's a decent article over at my old stomping grounds, DevHood, here: http://www.devhood.com/tutorials/tutorial_details.aspx?tutorial_id=466[^]
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi guys,
I have a Mdi Container that can be minimized to tray. So when when I click minimized button I Hide the form and I show the notify icon.
The problem is that during the mdi parent is not visible, maybe I have to create new mdi child form. To create it:
Form f = new Form();
f.MdiParent = this;
f.Show();
but if the mdi parent is not visible the show method block the main process and I have to kill it.
Why?
Thanks
|
|
|
|
|
I have a 32x32 256 color cursor resource file in my C# executable application as an embedded resource.
If I load the cursor from there, using
this.Cursor = new Cursor( Assembly.GetExecutingAssembly().GetManifestResourceStream( "CursurTest.X.cur" ) );
...then the cursor appears all-black, but the shape is same.
However, if I construct the cursor using User32.DLL's LoadCursorFromFile, which returns a Handle, then it is OK.
How can I use an embedded cursor resource properly? I do not want to put the cursor as an external file.
|
|
|
|
|
I am writing a toobar for displaying the annotations on a page .I need to access the highlited section on the page in the browser .How do access an instance of a browser using C# . What are the classes/interfaces for this . Using those classes how do i get the highlited section on the page .
(ie if i make a text selection using the mouse how do i get this ).
How useful are the webbrowser class and the iwebbrowser2 interface .The webbrowser class is it used to access an instance of the browser or is the iwebbrowser2 interrface used to access the browser instance
Srikar Y
NITK Surathkal
|
|
|
|
|
In COM programming, you always access servers (those implementing the functionality, ex. WebBrowser control) via their interface. In C++, you are given the WebBrowser's IUnknown as a site, which you can QI for the IWebBrowser2 interface and use that to access the COM control. Since you're in the C# forum, I assume you're using .NET. In this case, you get an interface to the web browser however your implementation gives it to you.
Since I don't know what implementation you're using, I can't solve your problem but can at least give you some idea of what is wrong.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
I have a stylesheet XML structure, represented by a class with a dictionary of attributes in it. These attributes are all serializable in one way or another, but they are not always directly serializable to XML - sometimes they must be serialized as binary data.
If this stylesheet is saved as a file, I want it to be an XML file, in which case the bitmaps, etc, could be saved to individual files. If it is serialized (to a resource, etc), I don't care whether it's human-readable or not.
So I'm dealing with two different types of serialization of two different types of data. What do you think is the best choice? :
Serializing to a file:
<list>Serialize all non-XML data (bitmaps, etc) to separate filesStore the non-XML data as hex/Base64 directly in the XML nodesStore the non-XML data in separate nodes at the bottom of the XML fileStore the non-XML data in a single binary serialization fileBinary Stream/Resource:
<list>Serialize all non-XML data (bitmaps, etc) to separate streamsStore the non-XML data as hex/Base64 directly in the XML nodesStore the non-XML data in separate nodes at the bottom of the XML textStore the non-XML data in a single binary serialization stream and the XML data in anotherStore both the XML and the non-XML data in a single binary stream
|
|
|
|
|
OK, what I've decided to do is this: embedding of Base64 is allowed in both file and resource versions. If someone wants to use file bitmaps, they can just use a path instead of bitmap data.
Kinda obvious, huh?
|
|
|
|
|
Hi Friends,
I want to transfer the data across the Process , which is the least time consuming way? (Not for coding but for performance !)
VikramS
|
|
|
|
|
In .NET, two processes are bound by different contexts, namly AppDomains. To do this, you must either P/Invoke A LOT of code, or use .NET Remoting. There are several great sections about .NET Remoting in the .NET Framework SDK, and it is the recommend method for doing so (because it is the least time-consuming way, and is the "correct" way between two .NET applications).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|