|
A System.Data.SqlClient.SqlException has an Errors array which contains the specific error(s).
I search it for 2601 (unique index violation) or 2627 (primary key violation), and if present I wrap it in a custom exception.
You can take a look at my DatabaseAccessor article which contains an enum of the code I support.
|
|
|
|
|
Hello everybody scenario is as follows:
Application multithreaded in windowsForms
C# Language
Framework 2.0 in VisualStudio 2005
This application works with several business logic processes asynchronous manner.
Play audio and video with DirectX
Handles timers who control the times of execution.
Everything works correctly while not use objects pictureBox with animated images (GIF). When I need to load an Animated Gif in a pictureBox and view the animation at run time, the processor is fired at a 100%, that happens only with a lively Gif image. Using a JPG or PNG static images, the performance is not affected. But implementation requires at least play 10 Gif animated, distributed in the Form.
When you try to load all these images, many are not displayed in the pictureBox and those displayed lose animation or reproduce them too slowly and with a delay that makes Losing the aesthetics chart.
To accomplish this I found some documentation msdn Class ImageAnimator, which to deploy in a component created for myself, I get the same problem of performance that picture box.
If anyone has an idea of what's going on and how to solve am waiting for their early comments.
Thankyou.
|
|
|
|
|
I'd avoid the picture box and draw the images yourself. The picture box doesn't handle animated gifs, so you must have your own code in there somewhere already, right ?
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
i am trying to export a excel file to the user when they click a button, i tried Response.WriteFile("filename"), it only display the content in the same page, can someone tell me whats the code to prompt them with a save as option? Thank you in advance.
|
|
|
|
|
I think I just answered this in the VB forum. The ASP.NET forum is the only forum that is right for this question, please don't crosspost
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
sorry for the crosspost, i was a bit impatient, and thank you for your help, Regards!
|
|
|
|
|
Hi
I have the code below to minimize my form to the systemtray and bring it back up when the notifyicon is doubleclicked.
When the form is minimized some log-information is added in a richtextbox and I want the errors to be shown in red, so I set the selectioncolor to red.
My problem is that this only works if the form is in it's normal state otherwise all the text added will be black.
Does anyone know why I can't set the selectioncolor when the form is minimized?
private delegate void UpdateInfoDelegate(string newEvent, Color c);
private void UpdateInfo(string newEvent, Color c)
{
rtbInfo.SelectionColor = c;
rtbInfo.AppendText(newEvent);
rtbInfo.SelectionColor = Color.Black;
}
public void SetInfoText(string text)
{
rtbInfo.Invoke(new UpdateInfoDelegate(UpdateInfo), DateTime.Now + " " + text + "\r\n", Color.Black);
}
public void SetErrorText(string text)
{
rtbInfo.Invoke(new UpdateInfoDelegate(UpdateInfo), DateTime.Now + " " + text + "\r\n", Color.Red);
}
private void Form1_Resize(object sender, EventArgs e)
{
if (WindowState == FormWindowState.Minimized)
{
Hide();
notifyIcon1.Visible = true;
}
}
private void notifyIcon1_DoubleClick(object sender, EventArgs e)
{
Show();
WindowState = FormWindowState.Normal;
notifyIcon1.Visible = false;
}
|
|
|
|
|
You have to do the append/coloring in this order: append, select appended text, set selection color. See this post on MSDN[^].
|
|
|
|
|
I have a dataset filled with names (1 table 1 collumn),
I then loop trough the dataset and add all of them as tree nodes to a treeview.
Then i want to aply a rowfilter after the rowfilter is set i want to loop trough the filtered set,
But evertime i do it nothing gets filtered it just displays everthing in the dataset.
I'm guessing that its my loop but im not sure:
for(int i=0; i < dataset_filter.Tables[0].Rows.Count; i++)
Rowfilter:
dataset_filter.Tables[0].DefaultView.RowFilter = "filter='" + filter.Text + "%'";
Thanks!
|
|
|
|
|
Hello,
I am executing a JScript class from my C# using Microsoft Jscript Engine, using reflection to invoke JScript.
If there is any exception thrown from JSCript, how to frame it properly for end user. I can handle the execption in try catch block, but i am getting TargetInvocation exception, which needs to be framed properly and shown to end user. Any Inputs in framing the TargetInvocation exception and showing to user in meaningful way?
Thanks
|
|
|
|
|
Hello,
I have a DataGridView that is dynamically populated and configured for row select, multiselect = no. When a row is double clicked, an event handler is fired which runs a function based on the Row index. The row index is referenced as follows:
myDgv.SelectedRows[0].Cells[2].Value.ToString()
This works great, until the user is holding the CTRL key while double clicking. I get an "index out of range error", making me think holding the CTRL key changes the value the above code returns.
Has anyone ran into this before? I'm not sure what to do, other than catch the error and fail the event. Any ideas are appreciated!
Thanks,
Alan
|
|
|
|
|
I think it may have something to do with the index being cell based rather than row based if I hold CTRL. CTRL modifies selection in Windows (as in selecting multiple files at once, or multiple listbox lines at once).
|
|
|
|
|
Ok, figured it out. When I doubleclick on a row while holding CTRL, the dialog selects the row on the first click, but deselects it on the second. The DoubleClick eventhandler fires, references the selected row, and fails as none are selected.
|
|
|
|
|
Hello everyone,
I know this one is a little tricky, but I hope someone has a
hint or an idea.
In our application occurs a StackOverflowException (at least
I think that) and the result is, that the application just
closes.
The problem is that I am not really sure which Exception
occurs because it happens sporadically and only at one of our
customers in different parts of our application.
So I have checked our code what will happens, when I manually
force some unhandled exceptions to occur. For example
NullReference, DivisionByZero, OutOfMemeory. No problem at
all. They all where handled by the Application.ThreadException
event. With a call stack and everything else that is nice to
have.
Then I tried StackOverflowException. The application crashes
and closes with a Dr. Watson hint. No stack trace and no clue
where to start searching.
Does anyone know how to log the call stack of an
StackOverflowException? (Of course without to install Visual
Studio on the customers workstations)
The application is developed in c# @ .Net Framework 2.0
Many thanks for every tip in advance...
modified on Thursday, December 06, 2007 4:55:21 AM
|
|
|
|
|
According to http://msdn2.microsoft.com/en-us/library/system.stackoverflowexception.aspx[^]...
<br />
In prior versions of the .NET Framework, your application could catch a StackOverflowException object (for example, to recover from unbounded recursion). However, that practice is currently discouraged because significant additional code is required to reliably catch a stack overflow exception and continue program execution.<br />
<br />
Starting with the .NET Framework version 2.0, a StackOverflowException object cannot be caught by a try-catch block and the corresponding process is terminated by default.<br />
Does that help?
Please don't bother me... I'm hacking right now. Don't look at me like that - doesn't anybody remember what "hacking" really means?
|
|
|
|
|
Thank you, I have also read that and that gave me no hope. So the best is to switch back to Framework 1.0
I cannot believe there is no way to catch such a fatal exception.
I have tried to create a new AppDomain…
I have tried to start the whole app in a separate Thread…
But everything I do the application still crashes.
|
|
|
|
|
I am using Treeview in a C# windows form. The data entered into the tree is a hierarchical listing of table definitions associated in groups of various depth off of the Treeview root.
I am looking for a class or routine where I can navigate through each Treeview node and node/child, get the value of the element so i can process the output.
I have a rudimental listing of this through the first 2 nodes (with testing ), but this requires some more elaborate coding, maybe recursive:
<br />
String nodeName = "";<br />
int nodeNum = 0;<br />
int i = 0, j = 1, k=0, cnt=0, lstNode=0;<br />
nodeName = treeView1.ToString();<br />
if (treeView1.Nodes.Count > 0)<br />
{<br />
for (i = 0; i < treeView1.Nodes.Count; i++)<br />
{<br />
nodeName = treeView1.Nodes[i].Text.ToString();<br />
cnt = treeView1.Nodes[i].GetNodeCount(false);<br />
if (cnt > 0)<br />
{<br />
lstNode = treeView1.Nodes[i].LastNode.Index;<br />
lstNode = treeView1.Nodes[i].LastNode.Level;<br />
for (j = 0; j < cnt; j++)<br />
{<br />
try<br />
{<br />
nodeName = treeView1.Nodes[i].Nodes[j].Text.ToString();<br />
}<br />
catch (Exception e)<br />
{ <br />
nodeName = "Undefined"; <br />
}<br />
}<br />
}<br />
}<br />
}<br />
This needs to be refined so that I can see ALL child elements no matter how deep they are in the Treeview.
Can anyone help?
|
|
|
|
|
You will need to write a recursive function to iterate through all nodes of a treeview
|
|
|
|
|
That is my assumption as well, but I have not written a recursive function in quite awhile. Can anyone give me push in the right direction on this? Code samples or what not?
|
|
|
|
|
Without wanting to get into the exact details of the code, it would normally look like this:
public void WalkNode(TreeNode node)
{
if (node.Nodes != null)
{
foreach (Node child in node.Nodes)
{
WalkNode(child);
}
}
}
|
|
|
|
|
Thank you very much. I was ot looking for the exact details of the code segment, just the outline for now. It has been a long time since doing any recursive programming (avoid like the plague) and am out of practice.
Thanks again.
|
|
|
|
|
Is it possible to find the name of the property for which an instance of an object is assigned to? ie: From inside an instance of an object that is assigned to a property of another object, I want to know the name of the property that that object is assigned to?
For example, you have a "Person" class that has a "MailingAddress" property and a "ShippingAddress" property, with each of these containing a general "Address" class object. From inside the instance of the "Address" object that is assigned to the "ShippingAddress" property, how do I find that this instance is assigned to the "ShippingAddress" property or the "MailingAddress" property? Or more generally, how do I find the name of the property for which an instance of an object is assigned to?
I would like to be able to do this without having a reference to the parent "Person" object; just determine the declaring property's name from any instance of an object.
Ultimately, I would like to define a string that contains the "path" down through an object hierarchy from property to property. For example, create a path string such as: "Person.ShippingAddress.ZipCode", which can be parsed later to in order to set the "ZipCode" property to a specific value for a Person. This example is somewhat trivial, but I need to be able to create this "path" for any object in order to set that object's property values for testing purposes. ie: Given that I know I will start with some parent object (in this case a Person object), I want to parse the path string so I can drill down through the Person class in order to set certain property values and then test the reaction of the program to those newly set values. Having the path string allows me to automate this testing process.
Reflection seems to work well when you want to drill DOWN into a class, but how to you start with an instance of an object and work your way back UP?
Thankyou for your time. Joby
|
|
|
|
|
I forget the details, but it's possible to get a call stack in code, I believe.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
You could always use the Stack for this. Try looking at the StackFrame class for this.
|
|
|
|
|
I am on my way towards building my own "Automated Call Distribution", IF any has any clue for CTI or TAPI in .net 2.0 please let me know.
Thank you!
M. Nauman Yousuf
"Mess with the Best, Die like the rest"
|
|
|
|