|
Specifically for your example, you could use a try /catch inside finally , thus:
try {
}
catch (Exception ex) {
}
finally {
try {
con.close();
}
catch (Exception ex) {
}
finally {
con = null;
}
}
Easy (and with tags too)
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
I'd recommend using a guard clause instead. I know you've answered the OP here, but it's better to do the following:
try
{
}
catch (...)
{
}
finally
{
if (conn.Open)
conn.Close();
}
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Probably better [he says after checking that is exactly what I have done] but I do have the closure in the finally block inside it's own try/catch.
Panic, Chaos, Destruction.
My work here is done.
|
|
|
|
|
Wouldn't
using (whateverConnection conn = new whateverConnection())
{
try
{
}
catch
{
}
}
be a better approach for the OP?
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
finally
{
if(con != null)
con.close() ;
}
modified 27-May-14 5:30am.
|
|
|
|
|
Hi.
I'm a total beginner in C# (and PC programming), but I'm starting to get the logic to work allright so I've got some hours in front of the computer. A couple of days ago I wanted to throw my own exception and I used the intellisense codesnippet to generate a new custom exception class. This works great and I have no problems using it, however I do not fully understand WHAT the lines of code actually do (how they work and what they are for). Since I got it working, I guess I really don't have to know what it does (since it is in fact working), however to expand my knowledge (and possible learn some tricks for the future) I would like to know what each line of the auto-generated code actually does, and what it is for.
Would anyone please do a quick explain of the code? I have pasted the auto-generated code here:
[global::System.Serializable]
public class IndexException : Exception
{
public IndexException() { }
public IndexException(string message) : base(message) { }
protected IndexException(
System.Runtime.Serialization.SerializationInfo info,
System.Runtime.Serialization.StreamingContext context)
: base(info, context) { }
}
|
|
|
|
|
Have a look here[^] and here[^]
only two letters away from being an asset
|
|
|
|
|
Thanks a lot!!
I've already seen the msdn article (which for me who don't know very much about PC programming yet did not help my understanding very much). However, the other article looks great!!
Thanks again!
|
|
|
|
|
Hi Friends !
I need some help on Web Browser Control.
If anybody has worked with this control pls share your ideas!
waiting for your ping...(reply)
thanks
|
|
|
|
|
vats the pblm using webbrowser control?Have u tried that?
Plz avoid using Need Help ! as subject line, instead specify your specific subject
|
|
|
|
|
i am using the code like bellow, but it does not work
SHDocVw.InternetExplorer browser;
browser.FileDownload += new DWebBrowserEvents2_FileDownloadEventHandler(browser_FileDownload);
void browser_FileDownload(ref bool Cancel)
{
}
while i download all the event is not fired.
but other events like browser.DocumentComplete, browser.BeforeNavigate2 etc is fired properly
do u have any suggestion
|
|
|
|
|
jasome wrote: SHDocVw.InternetExplorer browser;
browser.FileDownload += new DWebBrowserEvents2_FileDownloadEventHandler(browser_FileDownload);
Is InternetExplorer the WebBrowser control?Which event having this line of code?Have you put a break point and check 2 see if this event is firing at any stage?
|
|
|
|
|
 Well i just give the entire code block.
private SHDocVw.InternetExplorer browser;
private SHDocVw.ShellWindows shellWindows;
private ArrayList Current_IE_Handles;
#region Constructors
public Form1()
{
InitializeComponent();
Current_IE_Handles = new ArrayList();
shellWindows = new SHDocVw.ShellWindowsClass();
shellWindows.WindowRegistered += new SHDocVw.DShellWindowsEvents_WindowRegisteredEventHandler(shellWindows_WindowRegistered);
shellWindows.WindowRevoked += new SHDocVw.DShellWindowsEvents_WindowRevokedEventHandler(shellWindows_WindowRevoked);
}
#endregion
private void shellWindows_WindowRegistered(int z)
{
string filnam;
foreach (SHDocVw.InternetExplorer ie in shellWindows)
{
filnam = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();
if (filnam.Equals("iexplore"))
{
browser = ie;
bool check = true;
for (int i = 0; i < Current_IE_Handles.Count; i++)
{
if (Current_IE_Handles[i].ToString() == browser.HWND.ToString())
{
check = false;
}
}
if (check == true)
{
browser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(browser_DocumentComplete);
browser.FileDownload += new DWebBrowserEvents2_FileDownloadEventHandler(browser_FileDownload);
}
}
}
}
void browser_FileDownload(ref bool Cancel)
{
}
After running this program
when you open Internet Explorer(IE) the DOM object will be created.
and when ever the changes happens in the IE(navigate,document completer,) event will be fired.
using that i have traced all the visited urls,popups,print activity,etc but i dont get event fired for File Download
thanks
|
|
|
|
|
Stop reposting. Your question below had a more appropriate title.
only two letters away from being an asset
|
|
|
|
|
thanks for the comment,
i do so !
Try Different Do Best
Jacob
|
|
|
|
|
Hi all,
Is there any event available to trace file download using C#?
for example : downloading file from GMAIL.
thanks
|
|
|
|
|
jasome wrote: Is there any event available to trace file download using C#?
vat u mean by trace file download?
|
|
|
|
|
thanks for your reply.
i need to get just an event, while downloading the file from IE.
from that i want to know the files that are downloaded.
thanks
|
|
|
|
|
|
Hello,
I'm reading a MID file a nokia ringtone file and I want to convert every byte in it to octet then to hex but I don't know how? I am searching how to sen ring tones?
Thanks
Dad
|
|
|
|
|
To convert byte -> octet and byte -> hex :
byte myByte = 250;
string octet = Convert.ToString(myByte, 8);
string hex = Convert.ToString(myByte, 16);
To send the ring tone, I think you must use the AT command from nokia, see the Manual.
Search it in nokia website for AT command.
Then use SerialPort class for writing AT command to phone.
|
|
|
|
|
I was looking at the Convert Class but not familiar with it and didn't want to do too much reading for someone else
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
so... no reading -> no answer next time.
|
|
|
|
|
But I gave an answer to 1 of the two conversions, surely that is allowed?
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
I am confused as why you need to convert a Byte to either octet of hex in order to send data? after all both Octet and Hex are just different was to display a byte value. If you want to convert a byte (or int) to string values for hex then...
string hex = myInt.ToString("X");
...I'm not sure of an easy way to convert an int to octet string thou sorry
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|