|
Write your own custom collection editor and make a deep copy of the object which you're trying to edit before displaying it in the collectio editor form you'd create. The reason this is happening is because the collection editor is responsible for editing the collection. The objects in that collection are references to objects elsewhere, something the collection editor does not care about. By making a deep copy of the collection you are creating new objects to which the collection of objects reference. Depending on your implementation, though, this might now work.
Say that the collection references a bunch of controls in your form. If you make a deep copy, edit it, and replace the original copy you have to remove all the old controls from the Controls collection of the control or form and add the new ones. If all the collection contains is a bunch of strings, ListViewItem s, etc., then this is probably okay to do.
You could make it easy and extend the CollectionEditor , override EditValue , and re-use the CollectionEditor.CollectionForm . Just remember to change the EditorAttribute on the property that is of the collection Type (or on the collection class itself).
One final option uses the DesignerTransaction , though I don't know if it'll work in this case. Since an IServiceProvider is passed to the UITypeEditor.EditValue , you could try getting the IDesignerHost service and call CreateTransaction on it to create an associated DesignerTransaction . You can then commit or undo a batch of operations. You could do something like this:
protected override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider, object value)
{
DesignerTransaction trans = null;
IDesignerHost host = provider.GetService(typeof(IDesignerHost));
if (host != null)
trans = host.CreateTransaction();
IWindowsFormsEditorService forms = provider.GetService(typeof(
IWindowsFormsEditorService));
try
{
CollectionForm form = new CollectionForm(this);
form.EditValue = value;
DialogResult result = form.ShowEditorDialog(forms);
if (result == DialogResult.OK)
{
value = form.EditValue;
if (trans != null) trans.Commit();
}
else if (trans != null) trans.Cancel();
}
catch
{
if (trans != null) trans.Cancel();
}
return value;
} This is a very simple example and untested, but the concept is sound so long as you can use the DesignerTransaction from this context (and I don't see why you couldn't). Read the documentation for the DesignerTransaction in the .NET Framework SDK for more information and an example.
-----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-----
|
|
|
|
|
We have developed a C# application with Studio 2002 and framework 1.0.
In this app, we have about 10 sockets that communicate through tcp/ip and we
also have some 'platform invoke' calls to a third party dll along with numerous
calls to a SQL 2000 Server to log different events.
Today we had a 'crash' and the following popup was displayed:
**************************
Microsoft Visual C++ Runtime library
Assertion failed!
Program: ----
File: ..\..\..\nt\ssock\src\ntssockc.c
Line:1053
Expression: 1 == pConnection->fCallCheck
ABORT RETRY IGNORE
**************************
If we press ignore the program just continues and everything seems to be working.
But does anyone have a clue what has happened?
Could it be our program that does something wrong?
Could it be something in the framework?
Could it be the third-paty dll?
OR COULD IT BE SOMETHING WITH SQL SERVER? (I've found an article that suggests this)
Please respond if someone has an idea about this!
ip_tgz
|
|
|
|
|
It is obvious your error happend in your socket calling part which means it is happend in your third party dll.
Mazy
No sig. available now.
|
|
|
|
|
Are you sure about that?
This article suggests something else:
http://dbforums.com/arch/29/2003/2/695575
ip_tgz
|
|
|
|
|
It happpends at VC++ run time library and at file ntssockc.c which is for socket.Isn't it?
Mazy
No sig. available now.
|
|
|
|
|
Exactly what Mazdak said. The error happened in the VC++ runtime, not the CLR. If something croaked in the CLR, you'd get a SystemException (or derivative) and the dialog looks different and contains different information.
Since the error message is also giving you a filename, it's possible that you have debug symbols on your machine for the third-party library so you might want to try debugging your app.
In any case, it is possible that you called a P/Invoked function with a bad parameter and their library isn't validating params correctly, but the error still occured in their native library.
-----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-----
|
|
|
|
|
how can i controll devices (using c#) connected to my serial ,paralell,com and usb ports?
and in what subject do i need to read?
|
|
|
|
|
There is nothing in the .NET base class library that can do this out-right. There are, however, many articles here on CodeProject that deal with communicating to a few of these (I know they exist for serial and parallel ports). Just use the search at the top of any page.
-----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-----
|
|
|
|
|
Hello I am using Sql Server 2000 Developer Edition, Now I know there are limitations too how many connections you have BUT This piece of code below executes a whole lot slower the second time you run it.
switch(cbSearch.SelectedItem.ToString())
{
case "Lastname":
cmd = new SqlCommand("SPSearchRmiInfoLastname", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Lastname", txtSearch.Text);
break;
case "Firstname":
cmd = new SqlCommand("SPSearchRmiInfoFirstname", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Firstname", txtSearch.Text);
break;
}
conn.Open();
Search.Clear();
SqlDataReader drd = cmd.ExecuteReader();
while(drd.Read())
{
Search.Rows.Add(new object[] {drd[0], drd[1], drd[2], drd[3]});
sbp.Text = Search.Rows.Count+" records found.";
}
dg.DataSource = Search;
drd.Close();
conn.Close();
The results are staggering.
First time: 1783 Milliseconds
Second time: 150326 Milliseconds
HOLY SHAZBOT!!
Now that's a difference right there,
Any ideas on why this is happening and how I can change it
Thanks,
Obe
NOTE: I already posted this in the Sql/ADO/ADO.NET Section
but it has todo with C# as well
------------------
I'm naked under my clothes...
|
|
|
|
|
I can see that you have 2 different stored procedures. Is it always the same stored proc that is called the second time?
Also, as a piece of advice (not related to your problem), don't start you stored procedures name with "sp", because the server search for it in the "master" database when they begin with "sp".
--------
"I say no to drugs, but they don't listen."
- Marilyn Manson
|
|
|
|
|
Thanks for the advice in the naming schema...
As for the SP, when I was timing the differences I used the same SP executed one right after the other
------------------
I'm naked under my clothes...
|
|
|
|
|
Another quick performance tip (although it doesn't explain why it is slower the second time around)
Change your while loop to:
while(drd.Read())
{
Search.Rows.Add(new object[] {drd[0], drd[1], drd[2], drd[3]});
}
sbp.Text = string.Concat(Search.Rows.Count.ToString()," records found.")
Now you only generate your text once, which should speed things up. Also, I changes the stringA + stringB notation in to a string.Concat() method call which is a wee bit faster.
--Colin Mackay--
EuroCPian Spring 2004 Get Together[^]
"You can have everything in life you want if you will just help enough other people get what they want." --Zig Ziglar
|
|
|
|
|
Hi All,
I have a DataAdapter that I create in a middle data tier. Now if I called that middle data tier class and it creates that DataAdapter that is global in that class does it persist through the life of the App?
Thanks,
JJ
|
|
|
|
|
It will persist for the life of the class. Perhaps you want to make it static ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
So I call the class in my other class to do a function call and once that
function call is done so is the life of the class, correct?
Use said to make it static in global in the class then it will persist for the life of the App. Is this usually done in Database design apps?
Thanks,
JJ
|
|
|
|
|
MrJJKoolJ wrote:
So I call the class in my other class to do a function call and once that
function call is done so is the life of the class, correct?
If the class instance is created with a call to 'new' inside that function, yes.
MrJJKoolJ wrote:
Use said to make it static in global in the class then it will persist for the life of the App.
If it's a static variable in any scope then there will only ever be one instance of the class. If it remains the same instance, I'm not sure. On second thoughts, it may not solve anything at all. What needs to happen is simply that the instance of the class is created when your app starts and to be in a scope where it's not destroyed. In a desktop app, that would be the point where the main constructor is called, in an ASP.NET app, application start would be the way to go.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I have a relativly simple control used for a layout manager for a form, its hierarchy is similar to this:
Parent Form
WorkspaceManager : Component
WorkspaceManagerControl : Control
DockingWindow : Control
ContainerWindow : Control
If I inherit 'DockingWindow' from a panel it gives me design time support to put controls on it etc.. (or set the ScrollableControlDesigner as the designer attribute)
This is almost what I want. The problem is that the DockingWindow is infact the control which draws all the required title bar etc.. and the ContainerWindow is the control I want to be able to drop controls onto
The ContainerWindow is an internal member of DockingWindow and definitly gets created and sized within the docking window ( a quick look with Spy++ shows this ) If I inherit this from Panel or add the ScrollableControlDesigner property to it I do not get the design time to support to drop the controls onto?
Why? Im probably missing some sort of attribute, or maybe need to expose the ContainerWindow as a property with some special attribute but I dont know what.
Any help/direction would be appreciated here.
Thanks - James
James Simpson
Web Developer
imebgo@hotmail.com
P S - This is what part of the alphabet would look like if Q and R were eliminated Mitch Hedberg
|
|
|
|
|
Dirty Solution so far
WorkspaceManager as the DockingWindows exposed as a DockingWindowCollection
I also exposed a collection of ContainerWindows as a ContainerWindowCollection
You need to create a docking window, then create a container window in the workspace manager and set the ContainerWindow property on the DockingWindow to the ContainerWindow you want to use within the window.
This seems to work so far...
Any more encapsulated solutions would be welcome )
Thanks - James
James Simpson
Web Developer
imebgo@hotmail.com
P S - This is what part of the alphabet would look like if Q and R were eliminated Mitch Hedberg
|
|
|
|
|
How to do synchronization to threads, for example if I have some number of nodes each have a thread and, also this nodes have some values for each node stored in an array, these values will be updated under some conditions “the one with min value will be updated first”, and the new value will be stored in the initial array.
How to do this?
nad
|
|
|
|
|
For information on thread synchronization, see the documentation for the System.Threading namespace in the .NET Framework SDK, specifically information about the Monitor (or use the lock keyword in C#) class which is the easiest to use (but not always appropriate). I also urge you to search this forum (use "Search Comments" above) and the CodeProject site for many examples and discussions. There have been several here in the C# forum similar to your problem in the recent past.
When using the lock keyword, the C# compiler generates the following:
lock(someObject)
{
Console.WriteLine("Hello, world!");
}
Monitor.Enter(someObject)
try
{
Console.WriteLine("Hello, world!");
}
finally
{
Monitor.Exit(someObject);
} someObject is an instance of an object and its scope depends on your requirements. Since you're synchronizing methods on different objects, you should use a static object like the Type of your class. So, if your class is called MyClass , then use lock(typeof(MyClass)) to make sure all threads are synchronized no matter which object is trying to access a resource (like your array). If you want to synchronize a resource that is specifically to a single instance of a class, then you can lock against this .
If you look at the namespace I mentioned before, there are many other synchronization objects that allow you to specify time-outs, share WaitHandle s, and more. There's also a topic in the .NET Framework SDK that should get you started: http://msdn.microsoft.com/library/en-us/cpguide/html/cpconthreading.asp[^].
-----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!
I'm trying to have my videos of our software
(which is to be burned onto a dvd or cd)
protected from copying. I mean, I dont want the user
to copy-paste the lot of them with a happy smile.
I'd like them to be read-only.
Of course, it would be nice if there exist a simple solution
-aka not too expensive or even free!- to this minor problem.
What are my options ?
thanks !
This by our hands that dream,
"I shall find a way or make one!"
|
|
|
|
|
Your options are to use google and not to post in the C# programming forum. This is not a programming question. There are solutions available, but everything is crackable. Just go to http://slashdot.org[^] to see what everyone thinks of them and how fast they're cracked (think: DeCSS).
-----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-----
|
|
|
|
|
Just FYI...
Most CD copy protection schemes really just end up making some legitimate customers unhappy in the longrun (in other words, the protection causes some people who bought the software to not be able to run it).
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
hi
i am working on an applicatin that will record all keyboard keys in a text file.... just like the keylogger do.... i have worked in windows services ... i have make that ... but my application is not working like a keylogger .... don't take it in negitative sight.... just for learning porpose... thx..
Mazhar Hussain
|
|
|
|
|