|
At least I'm a "self-rietous idiot" who can spell reasonably well.
I've only posted a little over 200 messages since I became a member of CodeProject in 2006, partly because I often have too much work to do to fool around here, partly because I usually take some time to craft responses the way I think people ought to respond. I don't dictate how much detail should be provided in messages or how much care should go into things like clear explanations, correct English grammar and spelling, or code examples that provide clear illustration. But just like you guys presumably do, I post the sort of messages I think the forums need. And you know what? I've had quite a lot of people who appreciated it. Every one of those is worth about a hundred of those smallminded responses I sometimes get that seem motivated by a need to point out that I am no better than them. If I never said I was better and the only reason people react this way is because I provide a decent answer to a question, that's fine by me.
It will be interesting to see if you take your own advice and just ignore me.
|
|
|
|
|
I tried to take this off the thread because in my opinion personal differences do not belong to a thread where someone asks about a try-finally block, nor do I think it is the place to discuss forum etiquette if that is what you attempt to make it look like you're doing.
Since you insist on polluting with this, I shall offer you one more insult for your fragile ego to consume today: You really are the biggest loser I've yet come across.
|
|
|
|
|
Since you're being such a pain in the back about this, I'll just keep it up.
musefan wrote: I said that the 'finally block' executes after the return - which to me is the same as saying "the return value is evaluated before the finally executes"
Well at this point I cannot just add to what you're saying, because the finally block of course does NOT execute "after the return" - that would be impossible. No part of a method executes after it has returned, and that certainly includes the finally. And saying that is the same "to you" doesn't make it right. If you say "that's what I *meant* to say" I'll just take your word for it, mainly because I don't really think it matters if it is true or not - my goal in contributing in forums is to put some stuff in here for the community to learn about, not to craft replies for you personally. (However, when you take it totally off the thread topic, I prefer to switch to personal messages unless my opponent is so rude as to force me to publicly defend myself.)
musefan wrote: I did not accuse you of 'stealing' my answer
Read your own reply that started this whole thing. Unless it was precisely that accusation, what content is there in the message? Are you trying to claim you just wanted me to know that you had already said the same thing I said? If so, why did you want me to have this piece of information?
musefan wrote: yeah maybe I could have handled it differently but you clearly misunderstood my answer and therefore instead of 'correcting' it then you should say you don't understand
First, I didn't correct you, I merely gave what I see as a better explanation. The closest I got to hinting you might have said something less than accurate was to say it was "a bit more subtle". To my mind, this was a way of acknowledging that my additional comment concerned minute details, but it seems to have upset you instead. Second, who are you to tell me what I should and should not post? I am in fact a big fan of saying "I don't understand", but not when I do.
|
|
|
|
|
Hi,
Your code wouldn't actually compile because you've scoped i to the try block but use it also in the finally block.
That said, any code of a method that executes at all *necessarily* does so *before* the method returns. BUT... your method, if you move the int i = 1; line before the try-block (so it can compile), will nonetheless return 1.
Logically you can think of it as transforming the code into something like this:
int i = 1;
try
{
int returnValue = i;
i += 3;
return returnValue;
}
catch
{
i += 3;
throw;
}
In other words, the finally code executes prior to returning, but everything else, including evaluating the return value, happens before. You can see this by taking your try-finally code, set a breakpoint at entry, and step through it using "step into" (F11 in the English Visual Studio).
However, while it is *possible* to write code that is a bit confusing using try-finally or try-catch-finally, in practice there is no real problem. Catch blocks are for error handling and finally blocks are for freeing up resources. The classic example is databases and transactions: Let's say your method needs to open a connection and start a transaction to insert a record into two tables. If either insert fails you want both to fail, ensuring the consistency of your database, and regardless of how the inserts go you must always close the connection before returning from the method. In other words, error handling consists of rolling back a failed transaction, and resource cleanup consists of closing (and thus freeing up) the connection. The code thus would be something like this:
SqlConnection cnx = new SqlConnection("Data Source=.; Initial Catalog=Northwind; Integrated Security=true");
cnx.Open();
SqlTransaction tx = null;
try
{
tx = cnx.BeginTransaction();
insertFirst();
insertSecond();
tx.Commit();
}
catch
{
if (tx != null) tx.Rollback();
throw;
}
finally
{
cnx.Close();
}
If any statement in the try-block fails, control passes to the catch block. If BeginTransaction() failed tx is null and no rollback is attempted; if anything else fails we have a transaction and it is rolled back. Whether or not the operation fails, the connection is closed before the method either returns normally or re-throws the exception that occured during the try-block.
Hope this helps!
|
|
|
|
|
Thank you for everyone's replies.
I saw one question that if there is the return statement in the try block, and when the finally is to be executed.
I thought that when return, the finally statement will not be executed. otherwise ,if input one return statement in the finally or change the variable value in the finally block, the result will be changed.
The code in the subject can not be compiled, because I define the variable i and j of the int type in the try block.
Now I modify them.
Following is the new code:
using System;
using System.Collections.Generic;
using System.Text;
namespace Finally
{
class Program
{
static void Main(string[] args)
{
int z = func1();
}
static public int func1()
{
int i = 1;
int j = 2;
try
{
i = 110;
j = 119;
return i;
}
finally
{
i += 3;
}
}
}
}
I find that the return statement can not be typed in the finally block.
From the asm code, we can find that the function save the return value and then jump to the finally block to execute. so the result will not be influenced.
Following is the asm code.
using System;
using System.Collections.Generic;
using System.Text;
namespace Finally
{
class Program
{
static void Main(string[] args)
{
int z = func1();
}
static public int func1()
{
00000000 push ebp
00000001 mov ebp,esp
00000003 push edi
00000004 push esi
00000005 push ebx
00000006 sub esp,38h
00000009 xor eax,eax
0000000b mov dword ptr [ebp-10h],eax
0000000e xor eax,eax
00000010 mov dword ptr [ebp-1Ch],eax
00000013 cmp dword ptr ds:[00AE8364h],0
0000001a je 00000021
0000001c call 792611C6
00000021 xor edx,edx
00000023 mov dword ptr [ebp-3Ch],edx
00000026 xor edx,edx
00000028 mov dword ptr [ebp-40h],edx
0000002b xor edx,edx
0000002d mov dword ptr [ebp-44h],edx
00000030 nop
int i = 1;
00000031 mov dword ptr [ebp-3Ch],1
int j = 2;
00000038 mov dword ptr [ebp-40h],2
try
{
0000003f nop
i = 110;
00000040 mov dword ptr [ebp-3Ch],6Eh
j = 119;
00000047 mov dword ptr [ebp-40h],77h
return i;
0000004e mov eax,dword ptr [ebp-3Ch]
00000051 mov dword ptr [ebp-44h],eax //save the return value
00000054 nop
00000055 mov dword ptr [ebp-20h],0
0000005c mov dword ptr [ebp-1Ch],0FCh
00000063 push 0E311B7h
00000068 jmp 0000006A
}
finally
{
0000006a nop
i += 3;
0000006b add dword ptr [ebp-3Ch],3
}
0000006f nop
00000070 pop eax
00000071 jmp eax
00000073 nop
}
00000074 mov eax,dword ptr [ebp-44h]
00000077 lea esp,[ebp-0Ch]
0000007a pop ebx
0000007b pop esi
0000007c pop edi
0000007d pop ebp
0000007e ret
0000007f mov dword ptr [ebp-1Ch],0
00000086 jmp 00000073
|
|
|
|
|
Indeed; this is what I explained, but thanks for the disassembly to prove it.
Just one tip: Wrap your code in <pre></pre> tags and it will make a world of difference for readability!
|
|
|
|
|
|
I have the following code set up to iterate through an array making an http get request on each loop. The trouble I am having is that after about the 9th queue I start to get 503 : Errors from the server. Am I doing something wrong? This currently runs on a timer than runs every 5 seconds. I did alot of reading on this over the last couple days and it appears that I am properly reusing the objects, doing a netstat -an from my machine shows only one connection to the server, but I am essentially doing 17 http Gets every 5 seconds.
foreach (Queue queue in Queues)
{
try
{
string uri = "myProvider/com.broadsoft.xsi-actions/v1.0/user/" + queue.Number + "/queue";
XmlDocument xmlDoc = new XmlDocument();
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
webRequest.Credentials = new NetworkCredential("MyUser", "MyPass");
webRequest.Timeout = 5000;
webRequest.UserAgent = ".NET Framework Test Client";
HttpWebResponse wResponse = (HttpWebResponse)webRequest.GetResponse();
using (StreamReader responseStream = new StreamReader(wResponse.GetResponseStream()))
{
xmlDoc.Load(responseStream);
StringBuilder aHttpCallXmlOutL = new StringBuilder();
string tempString;
while ((tempString = responseStream.ReadLine()) != null) { aHttpCallXmlOutL.Append(tempString + "\r\n"); }
responseStream.Close();
wResponse.Close();
}
|
|
|
|
|
HTTP Error 503 means that the server is unable to handle the requests for some reason. This might be overloading or just an internal server setting that automatically refuses requests after a certain amount of requests in a certain timespan...
Maybe you should place some delay between your requests? Just an idea..
Phil
I won’t not use no double negatives.
|
|
|
|
|
I agree. I think the server is protecting itself against what could be deniel of service attacks as the requests are comming in so fast from the same IP.
I had similar issues a while back, when I was making a program to mine player stats from Blizzards Armory, and some delay did the trick for me.
|
|
|
|
|
Because I am using a Foreach loop and the flood control starts to happen while in my first foreach, how would you go about adding a delay?
I was toying with this thought last night and the best I could come up with was to create some type of a counter and then use the timer to call the web service, stepping through the the counter while I do that.
|
|
|
|
|
Thread.Sleep(yourInterval) after each loop for example...
I won’t not use no double negatives.
|
|
|
|
|
Hi
I am creating an Windows Application (C# Visual studio 2005) for Billing System
in that i want to enter the fields(Product name,price,unit price, total) in GridView Control.... Please guide me how to enter the data in Gridview control
Thanks in advance
|
|
|
|
|
Show the grid view with one blank row and then add one by one row if user press enter key in last one column of last row
For validation use onEdit and OnEndEdit events...
Best Regards,
Chetan Patel
|
|
|
|
|
Do you mean you want to bind the grid to some datasource?
If this is the case, then get the source of the data and bind to the grid.
e.g.
Say I have a datatable(dtBilling) as my datasource and my gridview name is dgBilling.
DataTable dtBilling = new DataTable();
dtBilling.Columns.Add("Product Name");
dtBilling.Columns.Add("Price");
dtBilling.Columns.Add("Unit Price");
dtBilling.Columns.Add("Total");
dtBilling.Rows.Add("Prod1", "100", "2.50", "250");
dtBilling.Rows.Add("Prod1", "200", "3.50", "3250");
dtBilling.Rows.Add("Prod1", "300", "4.50", "450");
dtBilling.Rows.Add("Prod1", "400", "5.50", "550");
if (dtBilling.Rows.Count > 0)
{
dgBilling.DataSource = dtBilling;
}
Hope this helps.
But to be honest, the question does not seem to be very clear to me.
Please let me know placidly, if you are looking a solution for this kind of problem or different!
Niladri Biswas
|
|
|
|
|
Hello,
I have registered one com dll and use it in my program.
When i create object of the class in com dll it shows one installation window and takes few times. still it works ok. but i want to shop showing the installation window.
I want to know the reason why this window is shown when it creates an object.
Best Regards,
Chetan Patel
|
|
|
|
|
Im intersted in teaching myself programing. Ive heard that c# is a good place to start. although everything ive read is way over my head. I need a first steping stone. Any help would be greatly appreciated. thank you
|
|
|
|
|
I believe that programming is something that can be learnt by practicing at least at the beginning .
Obviously, you need stuff to learn the new syntaxes, then the best practice to be followed, the way of writing, but above all it's the practice that matters.
Pick up any good book, mainly meant for beginners, practice the exercise probs, solve variety of programs, get a good grasp on the basic features like loop, switch, ternary operator, arrays, files, datastructures(list, dictionaries etc.)etc.,
Try to solve questions in the CodeProject forums and keep on till you feel comfortable in the basic levels.
Then move on to the next level.
Hope you will be comfortable within a time span of 6 months from now.
Niladri Biswas
|
|
|
|
|
Hey
C# is not a bad language to start with but i think vb would be much easier for beginners.
|
|
|
|
|
Blikkies wrote: vb would be much easier
But it leaves them stunted. Avoid the "easy" route.
|
|
|
|
|
hello to all
i m trying to display a windows form inside a web browser placed in a form
how it will possible to me
please help me
thanks
|
|
|
|
|
You can display a form anywhere you like. If you want your form to be limited to show inside your web browser control, write a form that is given screen bounds and does not allow itself to be moved outside them.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
Just out of curiosity: What inspired this winform in a browser in a winform design decision?
|
|
|
|
|
hello to all
i m a BS final year student i m having a problem with my project
i m unable to free fall the picture box from top to bottomm of the windows form i m using C#
can please anybody help me ?
|
|
|
|
|
Final year you say ? This is pretty trivial. I'd say that I would not use a picture box for this, but you can. Just set a timer, and modify the top property on the control, so that it moves down the form.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|