PlausiblyDamp
Administrators-
Posts
7016 -
Joined
-
Last visited
Content Type
Profiles
Forums
Blogs
Events
Articles
Resources
Downloads
Gallery
Everything posted by PlausiblyDamp
-
The catch block does two things, firstly it says what kind of exception you are interested in handling and secondly assigns it to a variable. catch (ObjectDisposedException) { } would catch an exception of type ObjectDisposedException, however it wouldn't assign it to a variable. catch (ObjectDisposedException ex) { } does the same thing but assigns the Exception to a variable named ex, this means you can access information regarding the exception within the catch block e.g. catch (ObjectDisposedException ex) { MessageBox.Show(ex.Message); } Like all variable names you cannot reuse an existing name from the same scope (e causes an error because e is already in use as a parameter name). The throw keyword is how you signal your own errors (similar to err.raise in vb6)
-
static public ChildForm Instance { get { if (_instance == null || _instance.IsDisposed) _instance = new ChildForm(); return _instance; } might be a better way of doing my original code - it now checks to see if the form is either null or has been previously closed / disposed.
-
pretty much spot on - making the constructor private prevents code outside of the ChildForm class calling it. Note the ChildForm class itself can still call this though. static private ChildForm _instance; just defines a private variable - again only accessible to the ChildForm class. The keyword static means that only one single instance of this variable exists in memory. If you have multiple instances of the ChildForm class they would all share this variable. In fact this exists without any actual instance of the ChildForm class. Pretty much spot on again. The code defines a read only property (a get but no set) that is public so it can be called from anywhere. Again the keyword 'static' means this exists at the class level and doesn't require an instance of the class to be created to call it. The return type is a ChildForm because it will return a valid instance of itself. All the property get does is delay the actual form creation until it is needed - if we have never accessed this property before then _instance is null so the Childform creates a new instance (it can call it's own private constructor) and stores it into the _instance field and then returns this to the calling code. If you step through the code you will see it still does something similar, it is just now internal to the ChildForm class and hidden behind the call to ChildForm.Instance
-
MDI is fine, a tabbed look like visual studio or something similar to Outlook with the options down the side might have a more modern look. If you have the time http://msdn.microsoft.com/en-us/library/aa480450.aspx is a very useful tool when developing these kind of applications (the tutorial included is pretty comprehensive as well). Getting to your original question of how to prevent duplicate instances however... One way to do this is prevent anything but the form itself creating an instance and let it manage the creation logic. Something like the following should give you an idea. //modified child form public partial class ChildForm : Form { private ChildForm() //prevents form being created from anywhere else. { InitializeComponent(); } static private ChildForm _instance; static public ChildForm Instance { get { if(_instance == null) _instance = new ChildForm(); return _instance; } } } //in the creating form use the following to get to the instance ChildForm f = ChildForm.Instance;
-
If you take the customErrors section out of the config file what happens?
-
If you are into LinQ as part of the newer 3.5 framework then http://www.codeplex.com/LINQtoAD is well worth a look.
-
The GC itself is quite sophisticated in how it handles allocations / collections, there isn't a single governing limit that is used... The benefit of garbage collection is allocations are cheap - it simply grabs more free memory (either already allocated and unused or more from the OS). Collection on the other hand can be expensive as it also compacts memory so all currently allocated memory is in a contiguous block - this helps to prevent fragmentation i.e. plenty free memory but all of it in small blocks here and there which collectively are big enough to fulfil a request but individually are too small which results in further allocations anyway... To reduce this overhead on collection .Net uses a generational collection system. When any resource is first allocated it lives in generation 0 - this is always physically allocated after the last currently allocated block of memory. Often variables are short lived (e.g. only last for the duration of a single method or as part of a short lived object) and these are ideal candidates for collection. If the GC deems it necessary to collect then it can attempt to collect and compact just generation 0. Any thing that is no longer needed is freed up while anything that survives is promoted to generation 1. As long as collection generation 0 frees up enough memory then it will just keep doing so - each object that survives a generation 0 collection is promoted to 1; the existing generation 1 objects are never looked at and stay at generation 1. If there isn't enough to be gained by just generation 0 objects then is can attempt a generation 1 collection. Any unused objects that are generation 0 or 1 will now be freed and the resulting memory compacted. This is a more intensive process than just a generation 0 collection. Any surviving objects are promoted again - 1s become 2s and 0s become 1s. 2 being the highest generation in the current implementation. If there isn't enough to be gained from a generation 1 collection then it has to do a full collection (generation 2) which is considerably more work than either a 1 or 0 collection. If you call GC.Collect() then you are forcing a generation 2 collection - this can result in a lot of objects getting promoted beyond their required generation and as a result they stay in memory longer. As well as these three generations there is an additional 'large object heap' from which objects that exceed 85000 bytes are allocated - this heap is collected after a generation 2 collection but is never compacted. As a starting guide .Net uses physical RAM as a guide for generation 2, while 0 and 1 are based on the cpu's level 1 and level 2 cache. Does that answer your question about the threshold? ;) Additionally the GC comes in a couple of 'flavours' multiprocessor machines have a slightly different mechanism to single processor ones while a server based OS is tuned to a slightly different application profile to a desktop OS. Also any object that has a finalizer registered will also survive it's first GC as it needs to have it's finalizer called to do clean up (this is why calling Dispose is recommended as it removes this step from the clean up process).
-
Have you assigned an icon to the tray icon?
-
I personally would avoid calling Application.Exit as it doesn't call the Finalizers of any instantiated objects - this can cause problems if the clean up code is required. If you close / Dispose of all objects when you have finished with them then closing the main form should exit the application. Equally calling GC.Collect is a bad idea - if you are closing / disposing of all objects that require explicit management then the GC should handle the rest by itself. In fact calling GC.Collect can cause objects to stay in memory longer than not calling GC.collect! Could you post the entire error message - or at least any modules it references as this could indicate where the problem lies. I would also check what version of the MySql driver you are using and if there are known issues with it - the fact you are getting an error relating to a semaphore indicates a threading issue and as your code isn't doing any explicit threading then the db driver is a prime candidate.
-
If the handler isn't enabled what happens if they do not specify a filename? You might be able to configure default.aspx to be the default page under IIS - never tried it when using an httphandler though.
-
Dim cd1 As New SaveFileDialog With cd1 .Title = "Save List" .Filter = "Text files (*.txt)|*.txt|Dictionary files(*.dic)|*.dic|All files (*.*)|*.*" .ShowDialog() Dim fs As New FileStream(.FileName, FileMode.Create) Dim sw As New StreamWriter(fs) For Each s As String In List1.Items sw.WriteLine(s) Next sw.Close() End With '{End Of}-> With CD1 is probably the closest / easiest translation.
-
aspreg_iis -pa "NT Authority\Network Service" + Windows Server 2000
PlausiblyDamp replied to mike55's topic in ASP.NET
What happens if you try to run the application? Are you getting any errors logged regarding the keystore? -
New starter at C# would like to ask some questions.
PlausiblyDamp replied to davearia's topic in Visual C# .NET
First question is easiest so ... In C# (and other 'C' like languages) strings can contain escape sequences, the '\' character is used to denote these. i.e. a new line is '\n' a tab is '\t' and so on. If you really want to use a '\' you have to double it up and use '\\' - not a problem but it can make cutting and pasting strings from other places a pain. Prefixing the string with a '@' symbol simply stops the esacping of the string and doesn't apply any special meaning to the '\' character. -
Sorry to see you go, but don't be a stranger for too long ;)
-
As a console app the following should work static void Main(string[] args) { EncryptString("Is there any method provided by VB for obtaining an eight byte hashcode from a string? The String's GetHashCode method seems to return a hashcode of 9, 10 or 11 bytes so is not quite what I'm after. Or should I design my own?", "password"); } private static void EncryptString(string text, string pass) { MD5CryptoServiceProvider hashMD5 = new MD5CryptoServiceProvider(); DESCryptoServiceProvider des = new DESCryptoServiceProvider(); byte[] hash = hashMD5.ComputeHash(Encoding.UTF8.GetBytes(pass)); byte[] key = new byte[8]; Array.Copy(hash, key, 8); des.IV = new byte[] {1,2,3,4,5,6,7,8}; des.Key = key; string res = Convert.ToBase64String(des.CreateEncryptor().TransformFinalBlock(Encoding.UTF8.GetBytes(text), 0, text.Length)); Console.WriteLine(res); Console.ReadLine(); }
-
Ads are causing squashed posts
PlausiblyDamp replied to MrPaul's topic in Suggestions, Bugs, and Comments
Surely the relevance of the ads make up for the inconvenience, after all if you are writing code to take a screen shot then you are almost guaranteed to want a new screen saver and a reel of bailing cord... -
Given the following three class definitions public class ClassA { public virtual void Something() {Debug.WriteLine("ClassA's version");} } public class ClassB : ClassA { public override void Something() { Debug.WriteLine("ClassB's version"); } } public class ClassC : ClassA { public override void Something() { Debug.WriteLine("ClassC's version"); } } then your code could be implemented as ClassA p_classA; ClassB p_classB; ClassC p_classC; int someInteger = 1; switch(someInteger) { case 1: p_classB = new ClassB(); p_classA = p_classB; break; case 2: p_classC = new ClassC(); p_classA = p_classC; break; // (.. and so on..) } p_classA.Something(); is that what you are after? In fact you could simplify it to ClassA p_classA; int someInteger = 1; switch(someInteger) { case 1: p_classA = new ClassB(); break; case 2: p_classA = new ClassC(); break; // (.. and so on..) } p_classA.Something();
-
If you drag the two controls to the page then you can set the AutoPostBack property of the drop down to true and it's items collection to the entries you want. Double click the drop down and you should be in it's SelectedIndexChanged (or something like that) event handler - in here you can refer to the drop down control's SelectedItem / SelectedIndex / SelectedValue property to discover which item was selected. The Image control has an ImageUrl property you can set to load the appropriate image.
-
How to add a newline with in a string being set to a label [C# 2005]
PlausiblyDamp replied to Shaitan00's topic in ASP.NET
If you are doing this in html then you will need to use a tag for a new line. -
How to pad a string with zero's so that "6" is "000006" [C# 2005]
PlausiblyDamp replied to Shaitan00's topic in General
[PLAIN]Re: How to pad a string with zero's so that "6" is "000006" [C# 2005][/PLAIN] As a quick example string s = "6"; s = s.PadLeft(6, '0'); -
Not tried this at all but if the article is to be beleived the calling syntax would be more like Dim result as String = AxShockwaveFlash1.CallFunction("name=\"callMeFromVB\" returntype=\"xml\">false");
-
The following should get you started LinearGradientBrush b = new LinearGradientBrush(new Rectangle(0,0,100,100),Color.Red, Color.Blue, 45f ); Bitmap bmp = new Bitmap(100,100); Graphics g = Graphics.FromImage(bmp); g.FillRectangle(b,0,0,100,100); bmp.Save("c:\\test.bmp");
-
You could have the button launch a thread to perform the work and when the event fires it terminates the thread. Alternatively the function could poll a variable to see if it should continue or stop and have the event simply set this flag.