|
The UITypeEditor has nothing to do with serialization. It's only an editor, hence the name. To get default serialization of your class, use the DesignerSerializationVisibilityAttribute to attribute your property, using the DesignerSerializationVisibility.Content enumeration member.
To customize serialization, implement your own CodeDomSerializer derivative for either your custom collection class or your property and attribute your collection class or property with the DesignerSerializerAttribute using the type of your CodeDomSerializer attribute. Several of the types mentioned above have examples in the .NET Framework SDK, which you can read online at http://msdn.microsoft.com/library/en-us/dnanchor/html/netfxanchor.asp[^] but that is also installed by default with VS.NET and the .NET Framework SDK stand-alone installer.
If you implement your own CodeDomSerializer be sure to set DesignerSerializerAttribute.Hidden or just don't use it at all.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
Is any one know, How to call CreateFileMapping in C#.
Thanks
|
|
|
|
|
|
Hi,
I'm developing a database sincronization application. I developed it and tried it using just console input and output (a simple console application). As the sincronizer is working OK I want to use it from a nice Windows Application.
I created a new Windows Application project, added some controls and I wrote this event handler:
private void Init_Click(object sender, System.EventArgs e)
{
Sincronizer Sinc = new Sincronizer();
Sinc.Start();
}
Sinc.Start() runs all the sincronization tasks. The problem is that when I run it, memory starts growing really fast (from 200Mb to 600Mb in seconds). I really don't know what I'm doing wrong, since the sincronizer object worked perfectly in my console application.
I would really appreciate some help
thanks,
Federico
|
|
|
|
|
Could you post more information on the Sincronizer object? What does the Start method do? Also, when it ran in an console application how was the memory usage?
~javier lozano
(blog)
|
|
|
|
|
Federico Milano wrote:
Sinc.Start() runs all the sincronization tasks. The problem is that when I run it, memory starts growing really fast (from 200Mb to 600Mb in seconds). I really don't know what I'm doing wrong, since the sincronizer object worked perfectly in my console application.
It's really hard to say anything without seeing any code: you could be doing almost anything in there.
You could try to comment out some portions of code until the leak stops, and try to show us a piece of code that's causing the leak.
Yes, even I am blogging now!
|
|
|
|
|
Sorry to say, but that doesn't help us answer your question at all. More code is required since no one here would know what Sincronizer is doing.
Guessing, however, you're probably not disposing connections, commands, or any other object that implements IDisposable . While managed objects are managed by the garbage collector (GC), the GC doesn't run unless 1) your application is idle, 2) your machine is running low on memory, or has been exhausted of all memory, or 3) you call GC.Collect , which is not recommended because it will block your threat while it finalizes objects. Good coding practices can get around that last problem by disposing objects correctly.
So, lets say in your implementation you re-use the IDbConnection implementation (for brevity, lets say you're using the System.Data.SqlClient ) like SqlConnection . Fine, just make sure you open and close it correctly. For each command that you create, however, you need to dispose it when done:
using (SqlCommand cmd = conn.CreateConnection())
{
cmd.CommandText = "insert into MyTable (ID, Name) values (1, \"Bob\")";
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
finally
{
conn.Close();
}
} The outer using statement makes sure the object is disposed, compiling to the following:
SqlCommand cmd = conn.CreateCommand();
try
{
cmd.CommandText = "...";
try
{
conn.Open();
cmd.ExecuteNonQuery();
}
finally
{
conn.Close();
}
}
finally
{
cmd.Dispose();
} As you should see, by expanding the try-finally blocks yourself instead of using using , you could eliminate an extra finally block which would improve performance a little in cases when an exception is thrown.
Also, if you're doing batch updates or inserts, use parameterized queries, re-using the same IDbCommand over and over. See SqlCommand.Parameters in the .NET Framework SDK for an example. While I'm at it, never use string concatentation for constructing SQL expressions - always use parameterized queries. This is far more secure (ever heard of SQL-injection attacks? string concatentation is the first step in making them possible) and actually alieviates quite a bit of your work when doing batch updates or inserts.
If you're using a DataSet to synchronize database, then you also need to dispose the DataSet otherwise it won't be disposed until your application is idle or until your memory is exhausted, which will happen long after you see a general drain on system resources (like CPU cycles).
Note that the disposable pattern doesn't mean the GC won't free your objects, like the "managed environment" means, but that you free the resources immediately. If you don't free them immediately it is not gauranteed when it will happen (taking into account the conditions I spoke of above and depending on the collection generation of the objects).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Thanks a lot for your answers. Maybe, I think, I'm hanging the UI thread because the Start() method is sycnhronous and doesn't return until it finishes. This would explain that when I was running this from the Console Application memory consumption was normal.
So, the question now is, how can I call this method without hanging the UI thread?
thanks,
Federico
|
|
|
|
|
Start it in a new thread:
Sincronizer s = new Sincronizer();
Thread t = new Thread(new ThreadStart(s.Start));
t.Start(); There's many other ways, too. Maybe your implementation of Sincronizer.Start starts itself in a thread (but make sure the caller knows to block before exiting; you can use Thread.Join for that). You could use a delegate and use BeginInvoke , and when you want to wait for it to finish you could use EndInvoke (which blocks until done (if not already), and returns any return value.
There is a catch: if you update any controls in your Windows Forms application, you need to use Control.InvokeRequired and Control.Invoke to invoke the method on the control in the thread on which the control was created. See the .NET Framework SDK documentation for either the property or method above for more information.
For more information on threading in the .NET Framework, read Threading[^] in the .NET Framework SDK.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I've (nearly) written a custom collection implementing IBindingList and ITypedList to use a datasource for the Datagrid.
The collection takes in the constructor the type of object the list will hold.
myCollection vehicleList = new MyCollection(typeof(Vehicle));
Using ITypedListGetItemProperties I then get a PropertyDescriptorCollection of Vehicle as the grid column header source. This all works fine.
However I intended that Vehicle could have a collection.
Public Class Vehicle<br />
{<br />
Class Vehicle(){}<br />
<br />
<br />
private MyCollection peopleList = new myCollection(typeof(People))<br />
<br />
public myCollection PeopleList<br />
{<br />
get{return peopleList;}<br />
}<br />
}<br />
when selecting this sublist as a link within the datagrid I'd like to re-use ITypedList.GetItemProperties to retrieve the public properties of type People.
So far I can identify the PropertyDescriptor for peopleList and it's type of MyCollection, but I can't get the instace of peopleList needed to retrieve it's collection type of People. From which I can then build the PropertyDescriptorCollection for People.
Is is possible to get the instance to which the propertyDescriptor is refering? If not I've wasted a lot of time getting this far
|
|
|
|
|
the last free name wrote:
So far I can identify the PropertyDescriptor for peopleList and it's type of MyCollection...
What exactly do you mean by "I can". Do you mean the code you've written can, you can through the debugger or through Type discovery? Please be specific.
Also, you really only need to implement ITypedList if you need to customize the properties exposed to bindable controls. Controls that implement binding correctly (like those defined in the .NET Framework Class Library) use the BindingManagerBase class for binding, from which CurrencyManager and PropertyManager derive. If you bind your collection of objects correctly (see the DataGridTableStyle.MappingName property for more information and an example) then you get binding for free.
Implementing IBindingList , on the other hand, is a custom feat that really depends on your requirements, but the basic implementation you also get for free. For example, if your collection (or, rather, list) returns true for IList.IsReadOnly then items can't be added and the UI appears appropriately.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I am trying to map my ArrayList of type CRelation to data grid. CRelation class has two properties Child and Parent, both are of type CTable
<br />
public class CRelation<br />
{<br />
public CRelation()<br />
{<br />
}<br />
private CTable m_oPrntTbl;<br />
public CTable Parent<br />
{<br />
set {m_oPrntTbl=value;}<br />
get{return m_oPrntTbl;}<br />
}<br />
private CTable m_oChldTbl;<br />
public CTable Child<br />
{<br />
set {m_oChldTbl=value;}<br />
get{return m_oChldTbl;}<br />
}<br />
}<br />
<br />
<br />
public class CTable <br />
{<br />
public CTable()<br />
{<br />
}<br />
<br />
private string m_szName;<br />
public string Name<br />
{<br />
set{m_szName = value;}<br />
get{return m_szName;}<br />
}<br />
}<br />
<br />
Now i want to map the grid column to Name property of the Child
I am using following code to map the property
<br />
DataGridTextBoxColumn dgcCol = new DataGridTextBoxColumn();<br />
dgcCol.MappingName = "Child.Name";<br />
Code above does not work.
Am i doing something wrong here?
Thanks
|
|
|
|
|
First of all, don't prefix your classes with "C". This is an obsolete naming convention in the .NET Framework and all other CLI implementations. It's important to remain consistent with the .NET Framework because it is a RAD environment (Rapid Application Development). Have any of the classes you've used in the .NET Framework Class Library started with "C" (sans classes like CollectionBase or Control )? You won't find a single one. Read Naming Guidelines[^] for more information.
Second, you really should read about the DataGridTableStyle.MappingName property. See http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemWindowsFormsDataGridTableStyleClassTopic.asp[^]. In it, it states that the DataGridTableStyle.MappingName must be set to the class name that the ArrayList - or just a simple array - contains. Your DataGridColumnStyle -derivatives then just contain the property name like Name .
The documentation above gives an example using a simple array, but an ArrayList works the same so long as you contain only one type (more than one type causes the first type to be used and any other types will not be bound).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
hello,
I'm trying to take a string from a dialog box and pass it to another form, here's my code
password.cs
<br />
...<br />
private String tmpPassStore;<br />
...<br />
private void pass_ok_Click(object sender, System.EventArgs e)<br />
{<br />
tmpPassStore=this.passText.Text;<br />
Form1.changePass(tmpPassStore);<br />
}<br />
form1.cs
<br />
...<br />
public String DBPassword ;<br />
...<br />
public void changePass(String pwd)<br />
{<br />
this.DBPassword=pwd;<br />
}<br />
but at compile time, I receive the following error:
D:\Projects\myBusinnes\password.cs(120): An object reference is required for the nonstatic field, method, or property 'myBusinnes.Form1.changePass(string)'
why??? I pass an object of type string...
Thanks in advance
Paolo
|
|
|
|
|
The compiler doesn't complain about the string.
To call the nonstatic method "changePass" of your "Form1" class you need an object of this class.
www.troschuetz.de
|
|
|
|
|
and excuse me how do I fix that??
Form1 calls password's form creating a new instance of the password object, how do I tell password's one to relay to form1 object?? thanks
Paolo
|
|
|
|
|
2 options:
1) Pass a reference to Form1 into the password form
2) Pass a delegate into the password form allowing callback to Form1
|
|
|
|
|
It's not working because Form1 doesn't exist in the context of the Password form. "There is no reference to an object of type Form1."
In other words, in Form1, it created an object of type Password (form). Form1 knows everything public about the Password object. The Password object, on the other hand, knows nothing of the object that created it (Form1). As a rule of thumb, Parent objects create child objects, know everything about them, and can manipulate them. Child objects know nothing of the parents that created them and, hence, can't directly modify them.
3rd option... Create a Public field on the Password form and have Form1 look at that field and retrieve the string itself. Instead of trying to pass the string from the Password form to Form1, have Form1 pickup the string from the Password form.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hello all,
I need to set the Initinal date in the DatetimePicker Control Blank not to today.
Thanks
Hay
|
|
|
|
|
It can't be blank. The DateTimePicker.Value is of a DateTime type, which is a value type. Value types cannot be null.
What you could do is make it appear that it has no value by using an empty DateTimePicker.CustomFormat property value and handling the ValueChanged event. When the Value changes to, say, DateTime.MinValue then set the DateTimePicker.Format to DateTimePickerFormat.Custom . Using a similar approach should give you the appearance of a blank date. You may need to use a value different from MinValue depending on the validation for the default DateTimePicker implementation. Whatever is outside the scope of your application would work.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello,
1) Create a Form
2) Add a TabControl
3) Add a AxWebBrowser Control on a TabPage
Run the app, everything works correctly.
Change the StartPosition property to WindowsDefaultBounds
Run the app, the form has strange dimensions Why?!?
Any idea?
Alberto Bencivenni
devDept Development Team Leader
Topology Optimization | Finite Element Method | Cad/Cam | OpenGL | Programming
|
|
|
|
|
hey...i have a bluetooth receiver attached to my PC's USB port. How can i access it through code...I wanna do things like search for devices in the raqnge, change the visible/invisible status, turn the device on on/off etc?
|
|
|
|
|
hey...could anyone tell me what are interface and how do u use them...eg Idisposable, Iserializable. Simplicity would be greatly appreciated.
Thanks
|
|
|
|
|
Interfaces are contracts that ensures your implementation (either a struct - though not a good idea, unless required because of boxing when casting to that interface - or a class or another interface) implements a certain method, property, or event. Read 13. Interfaces[^] in the C# Language Specification for more details, including the difference between implicit and explicit interface implementations.
As far as how to implement certain interfaces - or rather what they do - you really need to read in the .NET Framework SDK[^] what they do. Many of the topics in the SDK documentation give examples, and there's always more abstract documentation (about how to use Framework features, like serialization and the disposable pattern) if you read Programming with the .NET Framework[^].
Reading is important. Just guessing what they do would teach you the intricacies of how those interfaces work with other classes (like how IFormatter implementations use the ISerializable interface, and that Types must be attributed with the SerializationAttribute to be serializable - ISerializable just allows you to custom serialization of your Type).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Interfaces are the public methods/properties/events a class must have (exact same signature) in order to implement them.
For example, any class that implements IDisposable MUST implement 'public void Dispose()' method
You can cast any object into any interface it implements making it useful, among other many things, as a way of achieving polymorphism (dont know if thats the exact term in english).
|
|
|
|
|