-
1 Attachment(s)
First day of C# -
G'day all,
Today I downloaded the .net express package and did my first lot of c# coding.
I was just wondering if anyone can take a look at the code I wrote and just let me know of any bad habits I am falling into early on (as I'd like to fix any before I get into it too much) and anythings which you think I might be doing in an inefficient manner.
There isn't much, code, a bit under 100 lines at a guess.
Also, what version am I using? It's the 2008 express edition.
-
Re: First day of C# -
Hey there.
What does your application do? Ive downloaded it and looked at your code, but I havent ran the code as it seems to involve hiding windows.
Anyhow, your code looks very good. The only two things I can see directly are;
You've got a variable called "i" declared at class level, though it is only used in one method, so you should declare it locally in that method. A thumb rule is to keep every variables scope as narrow as possible.
At a point in your code, you're sleeping the UI thread. At any time you feel like you need to sleep the UI thread to solve an issue, you might need to rethink your logic. However when sleeping the thread is really needed, you must remember that sleeping the UI thread is a big no-no, as it'll make the application appear as not responding for the user.
Create a separate thread to run the code that has to be "put to sleep".
-
Re: First day of C# -
G'day,
Yeah, so far it does nothing - just wanted to make sure I wasn't in any bad habits like I got into when I entered VB6. Not sure if you know what WoW is (Well, everyone knows what world of warcraft is) but this is just going to be a multiboxing program. Just sets the windows up, broadcasts keys to appropriate windows and makes it easy to play 5 characters at once on one machine.
I'll make sure I remove that variable and place it where it should be.
I wasn't entirely sure how the sleep code works, but I'll make sure I fix that up. I am considering running it a different way because of that as I wasn't aware I could create a separate thread but now that I know that would work perfectly.
Thanks for your feedback :)