|
Hello!
Usually you won't catch all exceptions in your application by just having a single try/catch in your Main.
Put the try/catch around the block of code where you expect the SecurityException to occurr, then you should be able to catch it.
Regards,
mav
|
|
|
|
|
I completely realize how to do error handling in an application. I find it useful sometimes for debugging purposes to catch unhandled exceptions at the highest possible point, considering that they bubble up.
|
|
|
|
|
Considering your question and some rather unexpected and not really obvious behaviour of .NET I doubt you do.
Your program and exception handling will behave differently when run in the debugger than when started outside, for example, catching exceptions when run in the debugger but showing the default "an unhandled exception..." dialog when run outside VS.
That's something I've had to learn the hard way, too.
Try the following:
Create a new Windows Forms Project.
Add a second form to the project (Form2).
Put a button (button1) on your Form1 and a button (button2) on Form2.
Encapsulate your Application.Run(new Form1()); in a try/catch.
In the button eventhandler for button1 write
try<br />
{<br />
Form2 f2 = new Form2();<br />
f2.ShowDialog();<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show("Exception caught in button1_Click()\n"+ex.ToString());<br />
}
In the button eventhandler for button2 write
throw new ApplicationException("Test Exception");
Now run the application in the debugger, press button1 and then button2.
The exception is caught by the try/catch in button1_Click.
Now run the same application from explorer. The exception will NOT be caught, even though you have a try/catch in the button event handler AND in your Main() !
So either you do as I suggested and catch the exception where it's happening or consider adding an event handler for Application.ThreadException that's just rethrowing the exception from it's ThreadExceptionEventArgs . That way your application will behave the same in the debugger and outside.
Regards,
mav
|
|
|
|
|
Is there any way to insert the date of a project's build into a string variable automatically in C# without me having to manually change the date? Thanks in advance.
John 3:16: "For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life."
|
|
|
|
|
Don't know about automatic...
I would use the PreBuild event, there you can call a simple generator which might create something like "CurrentData.cs", content would be then a simple "const string CURRENT_DATE=...".
----------------------
~hamster1
|
|
|
|
|
Pardon my ignorance, but how would I deal with the PreBuild event (e.g.- is it a member of a certain class in .NET or a feature of the Visual Studio .NET IDE?) or could you at least please point me in the right direction to help me out. I'd appreciate it.
John 3:16: "For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life."
|
|
|
|
|
In VS.NET, open Solution Explorer, right-click on your project (.exe).
Go to Properties > Common Properties > Pre-build...
What you type there is basically a batch file.
----------------------
~hamster1
|
|
|
|
|
Hi all, the app. allows the user to create/add multiple textboxes (let's say) via a button click. Each textbox is docked at the bottom of the last added one. How do I change the order or in other words, move the one at the end to the 2nd place for example..
thanks in advance..
Radgar
"Imagination is more important than knowledge." - Albert Einstein
|
|
|
|
|
I think you should use DockManager to achieve this.
http://www.codeproject.com/cs/miscctrl/DockManager.asp
Live Life King Size
Alomgir Miah
|
|
|
|
|
You can do this by changing the Z order of the controls. BringToFront() and SendToBack() modify the Z order.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
thank you Judah. I tried that before I posted but the user may add 100 controls and when you modify the z-order, the action get slower and slower.. Thank you anyway.
Radgar
"Imagination is more important than knowledge." - Albert Einstein
|
|
|
|
|
That's probably a bad idea adding hundreds of controls. Each control contains an expensive HWND, could you fake the adding of controls? You could send a WM_Paint event to make the control draw to a surface, drawing it multiple times...
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Homosexuality in Christianity
Judah Himango
|
|
|
|
|
it's a complicated usercontrol Judah. That's why I cannot do what you suggested. thanx anyway.
Radgar
"Imagination is more important than knowledge." - Albert Einstein
|
|
|
|
|
Hello,
I have a class that I want to serialize to a XML file, but I'm having problems serializing two kinds of properties:
1. A get-only Id (Guid ). It's not supposed to be changed, so in my business object it's read only, set by the constructor.
2. I have an array of decimal s. The property gives read only access to the array, allowing the caller to modify the decimal s in the array, but not the array itself.
When I serialize these properties, they don't appear in the XML. I can fix it by making them get/set, but I wouldn't like to. Is there something like an attribute I could use?
Thanks!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
You must implement ISerializabe to do custom serialization.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemruntimeserializationiserializableclasstopic.asp
Live Life King Size
Alomgir Miah
|
|
|
|
|
Yes, that's exactly what I need. Thanks!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
I have the following code in WinForm which kick off a periodic timed event every 10 millisecs. The event updates a count every 100 event calls. I expect the display to be updated every 10ms * 100 = 1 sec.
The actual value displayed in the label after 60 seconds is 3600. i.e. 60 event elapses every second.
By changing tmrTimersTimer.Interval it has no effect on the count i.e. it is still 3600.
What am I doing wrong?
private void evtLoad(object sender, System.EventArgs e)<br />
{<br />
tmrTimersTimer = new System.Timers.Timer(10.0);<br />
tmrTimersTimer.Elapsed += new <br />
ElapsedEventHandler(tmrTimersTimer_Elapsed);<br />
tmrTimersTimer.SynchronizingObject = this;
tmrTimersTimer.AutoReset = true;<br />
tmrTimersTimer.Enabled = true;<br />
<br />
tmrTimersTimer.Start(); <br />
}<br />
<br />
private void tmrTimersTimer_Elapsed(object sender, <br />
System.Timers.ElapsedEventArgs e) <br />
{<br />
if (++Count % 100 == 0)<br />
{<br />
lblCount.Text = Count.ToString();<br />
}<br />
}
|
|
|
|
|
|
Is the 54ms documented anywhere?
Does anyone have any recommendation how I can get a resolution of 5ms?
I am updating the display with real-time data every 5ms. I have used other timers but this causes the display to to be updated in an irregular manner. It is as thought that the timer is not executing at the correct time.
Thanks,
Liam
|
|
|
|
|
I was wrong, the 54ms resolution is for the Windows Forms Timer. This[^] says the max resolution is 10 ms.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
I have always found a way arounf this, but now i can't do that anymore. I have the following problem. In my main form i have lots and lots of members.. How can i modify them from within another class? How can i acces them at least? pls help me.. thx
|
|
|
|
|
Pass this to the other class, that way, the other class will get a reference to the form and can access/modify its members.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Thx.. Can you please show me how to do this? thx
|
|
|
|
|
Hey all, this post is going to sound a little strange, I hope I can explain things well enough. I am working on an application that uses the RSS 2.0 Framework (here on CodeProject) but I need to include the iTunes tags in the RSS file. I thought this would be simple enough but I am having problems with the serializing of the XML file. The iTunes tags are in the format <itunes:xxxxxx> but when the file is imported and serialized, the tags become <itune_0x003a_xxxxxx>, where 0x003A seems to be the hex representation of a colon character. Any ideas on things I can do to get around this?
|
|
|
|
|
It sounds like an issue when the xml file is serialized, the ":" is being treated as an illegal character. Unfortunately, I don't have any suggestions for getting around this problem.
|
|
|
|