Click here to Skip to main content
15,910,878 members
Home / Discussions / C#
   

C#

 
QuestionTeechart - change color of bar in bar chart based on values Pin
PleaseHelpCP3-Feb-11 22:49
PleaseHelpCP3-Feb-11 22:49 
QuestionEfficient way to handle search page Pin
Umair Feroze3-Feb-11 22:34
Umair Feroze3-Feb-11 22:34 
QuestionWindows program responding to win + d Pin
ayandelhi3-Feb-11 21:57
ayandelhi3-Feb-11 21:57 
AnswerRe: Windows program responding to win + d Pin
Luc Pattyn3-Feb-11 22:23
sitebuilderLuc Pattyn3-Feb-11 22:23 
GeneralRe: Windows program responding to win + d Pin
ayandelhi3-Feb-11 23:31
ayandelhi3-Feb-11 23:31 
AnswerRe: Windows program responding to win + d Pin
Luc Pattyn3-Feb-11 23:41
sitebuilderLuc Pattyn3-Feb-11 23:41 
GeneralRe: Windows program responding to win + d Pin
ayandelhi3-Feb-11 23:51
ayandelhi3-Feb-11 23:51 
QuestionC# method to restart the application Pin
ayandelhi3-Feb-11 18:56
ayandelhi3-Feb-11 18:56 
AnswerRe: C# method to restart the application Pin
Peace ON3-Feb-11 19:31
Peace ON3-Feb-11 19:31 
GeneralRe: C# method to restart the application Pin
ayandelhi3-Feb-11 19:56
ayandelhi3-Feb-11 19:56 
GeneralRe: C# method to restart the application Pin
ayandelhi3-Feb-11 20:05
ayandelhi3-Feb-11 20:05 
GeneralRe: C# method to restart the application Pin
Peace ON3-Feb-11 20:13
Peace ON3-Feb-11 20:13 
GeneralRe: C# method to restart the application Pin
ayandelhi3-Feb-11 20:18
ayandelhi3-Feb-11 20:18 
AnswerRe: C# method to restart the application Pin
Peace ON3-Feb-11 20:20
Peace ON3-Feb-11 20:20 
GeneralRe: C# method to restart the application Pin
ayandelhi3-Feb-11 20:30
ayandelhi3-Feb-11 20:30 
AnswerRe: C# method to restart the application Pin
Luc Pattyn3-Feb-11 21:53
sitebuilderLuc Pattyn3-Feb-11 21:53 
GeneralRe: C# method to restart the application Pin
ayandelhi3-Feb-11 23:32
ayandelhi3-Feb-11 23:32 
GeneralRe: C# method to restart the application Pin
Pete O'Hanlon4-Feb-11 1:48
mvePete O'Hanlon4-Feb-11 1:48 
GeneralRe: C# method to restart the application Pin
ayandelhi5-Feb-11 16:51
ayandelhi5-Feb-11 16:51 
QuestionGet GetKeyboardLayout for Active Window In Keyboard Hook Pin
Anubhava Dimri3-Feb-11 18:12
Anubhava Dimri3-Feb-11 18:12 
QuestionMulti Threading Pin
mj_developer3-Feb-11 13:35
mj_developer3-Feb-11 13:35 
AnswerRe: Multi Threading Pin
Luc Pattyn3-Feb-11 14:02
sitebuilderLuc Pattyn3-Feb-11 14:02 
Hi,

for starters, please use PRE tags rather than CODE tags; they preserve formatting and indentation, making it all much more readable (you could still edit the existing message!).

You have two threads executing the same code, no problem. Each of them has a main method with local variables on the stack, they will be distinct as each thread has its own stack.

You may have a problem due to the way instances of Random are seeded: if you don't provide an explicit seed, they derive one from the current time, however your non-commented Sleep(1000) probably takes care of that.

You do have a problem with the way you do your painting. I'm not going to explain all the things you did wrong, I suggest you read this little article[^].

One more comment: your objects could also hit each other, something your code is never going to detect as the bouncing balls have their state completely private.

Suggestion 0: modify all painting stuff, in accordance with the guide lines set out in my article.

Suggestion 1: create a Ball class, have it hold the state and all the code a ball requires; then instantiate two (or more) of them, and keep them in a generic list. If you use threads, hide them inside the Ball class.

Suggestion 2: you don't really need a new ball and thread when the current ball leaves the valid x-range; you could recycle the ball, give it a new location, direction, speed, what have you, and save on the system resources (threads are expensive, and aborting them isn't very nice).

Suggestion 3: you don't really need a thread for each ball, a single timer could be used to update each of the balls.

Suggestion 4: create some global way to detect collisions, it will need information about all walls and balls.

Smile | :)
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

AnswerRe: Multi Threading Pin
_Maxxx_3-Feb-11 18:47
professional_Maxxx_3-Feb-11 18:47 
QuestionDLL Registration Issue Pin
turc16563-Feb-11 6:57
turc16563-Feb-11 6:57 
AnswerRe: DLL Registration Issue Pin
jim lahey3-Feb-11 8:46
jim lahey3-Feb-11 8:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.