473,394 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Multithreading question...

Hi,

I've been playing around with C# and was trying to put together a small
application that uses multiple threads as a learning exercise. For a simple
(but fun <g>) sample project, I thought I would do a simple game like pong.
Unfortunately it isn't working. My approach was to create a thread for each
object (ball, paddle etc.) and have each thread draw it's "object" back to
the main form. I was able to get each thread to be able to update the Text
property of the form but not it's client area. I guess my main question is
what should be the proper approach? Is having multiple theads writting to
the same form a bad idea (very possible...remember I'm new to C#)? If it is
an ok idea, how should each thread gain access to the form's graphics/client
area?

Any help or pointers to samples or reading would be appreciated.

Thanks

Eric
Nov 15 '05 #1
2 1358
> I've been playing around with C# and was trying to put together a small
application that uses multiple threads as a learning exercise. For a simple (but fun <g>) sample project, I thought I would do a simple game like pong. Unfortunately it isn't working. My approach was to create a thread for each object (ball, paddle etc.) and have each thread draw it's "object" back to
the main form. I was able to get each thread to be able to update the Text property of the form but not it's client area. I guess my main question is what should be the proper approach? Is having multiple theads writting to
the same form a bad idea (very possible...remember I'm new to C#)? If it is an ok idea, how should each thread gain access to the form's graphics/client area?


read this carefully (all 3 parts)
http://msdn.microsoft.com/library/de...us/dnforms/htm
l/winforms06112002.asp
Nov 15 '05 #2
Just Browsing <Ju***********@somewhere.com> wrote:
I've been playing around with C# and was trying to put together a small
application that uses multiple threads as a learning exercise. For a simple
(but fun <g>) sample project, I thought I would do a simple game like pong.
Unfortunately it isn't working. My approach was to create a thread for each
object (ball, paddle etc.) and have each thread draw it's "object" back to
the main form. I was able to get each thread to be able to update the Text
property of the form but not it's client area. I guess my main question is
what should be the proper approach? Is having multiple theads writting to
the same form a bad idea (very possible...remember I'm new to C#)? If it is
an ok idea, how should each thread gain access to the form's graphics/client
area?


The *only* thread which should be changing the GUI is the GUI event
thread for the form. Use Control.Invoke and
Control.BeginInvoke/Control.EndInvoke to invoke a delegate in the right
thread.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jean-Yves Nief | last post by:
hello, I have written a script which is performing some tasks in multithreading mode: the main thread is opening a connection to a distant server and all the threads that I start will have to...
1
by: dixp | last post by:
I'm new to writing multithreaded apps and I have a design question. I have a winforms app and a class which has a method that does processing which is time intensive. I want the user to be able...
0
by: GianGuz | last post by:
In the following example Global is able to create and manage access to objects of any kind (even in a multithreading environment) with and index value attached to. So a Global<0, string> is a...
11
by: Mark Yudkin | last post by:
The documentation is unclear (at least to me) on the permissibility of accessing DB2 (8.1.5) concurrently on and from Windows 2000 / XP / 2003, with separate transactions scope, from separate...
16
by: Robert Zurer | last post by:
Can anyone suggest the best book or part of a book on this subject. I'm looking for an in-depth treatment with examples in C# TIA Robert Zurer robert@zurer.com
10
by: Marek | last post by:
Hi, I am analyzing Duwamish7 source code boundled with Visual Studio .NET 2003. Could anoybody explain why the Monitor.Enter and Monitor.Exit block is used inside a static constructor? The code...
2
by: Rich | last post by:
Hello, I have set up a multithreading routine in a Test VB.net proj, and it appears to be working OK in debug mode and I am not using synchronization. Multithreading is a new thing for me, and...
2
by: Multithreading problem in vb.net | last post by:
Greetings, I am new to multithreading and I am trying to implement it in my app. This application is distributed application which needs to refresh every say 5 secs to show some activities in...
6
by: MeowCow | last post by:
I will try and make my question with out being too long winded. I have been doing a lot of reading on how to do multithreading and I have implemented the code from the following example on...
7
by: Ray | last post by:
Hello, Greetings! I'm looking for a solid C++ multithreading book. Can you recommend one? I don't think I've seen a multithreading C++ book that everybody thinks is good (like Effective C++ or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.