.net-2.0

AddHandler/RemoveHandler Not Disposing Correctly

泪湿孤枕 提交于 2019-12-18 08:57:38
问题 Using the AddHandler method, if I never use RemoveHandler , will that lead to memory leaks in some conditions and situations? I'm not so sure about the truth of this. And are there other causes to memory leaks that are solely available in VB as opposed to C#? 回答1: Well usually it doesn't.. but the possibility exists. When you subscribe to an event, you basically give a delegate (a func pointer if you will) to your method to the event publisher, who holds on to it as long as you do not

Asp.net session expiry redirect to login page

 ̄綄美尐妖づ 提交于 2019-12-18 07:15:15
问题 What is the best way to redirect to the login page when the session expires. I'm using sessionState mode="InProc" Can I set this in the web.config file? 回答1: The trick to remember about the session expiration is that this happens in the the worker process running behind the scenes and there is no direct way to notify the user without going back to the server to check the state of things. What I do is I have the page register a Javascript block that will redirect the user to the login page

Asp.net session expiry redirect to login page

﹥>﹥吖頭↗ 提交于 2019-12-18 07:15:04
问题 What is the best way to redirect to the login page when the session expires. I'm using sessionState mode="InProc" Can I set this in the web.config file? 回答1: The trick to remember about the session expiration is that this happens in the the worker process running behind the scenes and there is no direct way to notify the user without going back to the server to check the state of things. What I do is I have the page register a Javascript block that will redirect the user to the login page

Storing an object that implements multiple interfaces and derives from a certain base (.net)

安稳与你 提交于 2019-12-18 06:48:37
问题 In .net, it's possible to use generics so that a function can accept arguments which support one or more interfaces and derive from a base type, even if there does not exist any single type from which all valid argument types derive. For example, one could say: Sub Foo(Of T As {IInterface1, IInterface2, SomeBaseType})(Param as T) and be allowed to pass any derivative of SomeBaseType which implements both IInterface1 and IInterface2. This will work even if SomeBaseType does not support

StringBuilder.ToString() throws OutOfMemoryException

别来无恙 提交于 2019-12-18 05:44:14
问题 I have a created a StringBuilder of length "132370292", when I try to get the string using the ToString() method it throws OutOfMemoryException . StringBuilder SB = new StringBuilder(); for(int i =0; i<=5000; i++) { SB.Append("Some Junk Data for testing. My Actual Data is created from different sources by Appending to the String Builder."); } try { string str = SB.ToString(); // Throws OOM mostly Console.WriteLine("String Created Successfully"); } catch(OutOfMemoryException ex) { StreamWriter

Reading “chunked” response with HttpWebResponse

人走茶凉 提交于 2019-12-18 04:00:25
问题 I'm having trouble reading a "chunked" response when using a StreamReader to read the stream returned by GetResponseStream() of a HttpWebResponse: // response is an HttpWebResponse StreamReader reader = new StreamReader(response.GetResponseStream()); string output = reader.ReadToEnd(); // throws exception... When the reader.ReadToEnd() method is called I'm getting the following System.IO.IOException: Unable to read data from the transport connection: The connection was closed. The above code

How to create a DBF file from scratch in C#?

瘦欲@ 提交于 2019-12-18 03:35:18
问题 I am trying to write a DBF file from scratch in my program. I want to create it, add some columns, and then add data to the columns X amount of times. My program will not need to read it in again, but other programs will. I've looked around for a solution to this, but all seem to assume an existing DBF file, whereas I want to make a new one. The purpose of this is to make the DBF part of an ESRI ShapeFile. Does anyone know how to do this? 回答1: Download Microsoft OLE DB Provider for Visual

Need I remove controls after disposing them?

不想你离开。 提交于 2019-12-18 03:11:44
问题 .NET 2 // dynamic textbox adding myTextBox = new TextBox(); this.Controls.Add(myTextBox); // ... some code, finally // dynamic textbox removing myTextBox.Dispose(); // this.Controls.Remove(myTextBox); ?? is this needed Little explanation Surely, if I Dispose a control I will not see it anymore, but anyway, will remain a "Nothing" in the parent controls collection? need I also, like MSDN recommends, remove all handlers from the control? 回答1: No, you don't. I tried it. You can paste the

Override Property with different compatible Type

偶尔善良 提交于 2019-12-18 02:12:26
问题 I need a base class with a property where I can derive classes with the same property but different (compatible) types. The base Class can be abstract. public class Base { public virtual object prop { get; set; } } public class StrBase : Base { public override string prop { get; set; } // compiler error } public class UseIt { public void use() { List<Base> l = new List<Base>(); //... } } I tried it with Generics but that gives me a problem when using the class, because I want to store

How to sort an array of FileInfo[]

可紊 提交于 2019-12-17 23:38:17
问题 I have the following code DirectoryInfo taskDirectory = new DirectoryInfo(this.taskDirectoryPath); FileInfo[] taskFiles = taskDirectory.GetFiles("*" + blah + "*.xml"); I would like to sort the list by filename. How is this done, as quickly and easily as possible using .net v2. 回答1: Call Array.Sort, passing in a comparison delegate: Array.Sort(taskFiles, delegate(FileInfo f1, FileInfo f2) { return f1.Name.CompareTo(f2.Name); }); In C# 3 this becomes slightly simpler: Array.Sort(taskFiles, (f1,