473,396 Members | 1,898 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,396 software developers and data experts.

threading in winforms and the timer control

Just some threading questions
1. in a MDI app if you have multiple child forms, does each child
form run in its own thread ? Eg do you get error trying to update one
control on form1 from form 2

2. if you have a timer control running on a childform, and you either
a. minimize or

b. hide the form or

c. the form is no longer the currently selected form ,
does the timer keep running or does it stop ?

3. if you have a timer or a thread running on a child form, and you
close the form or end the application, do you have to stop the thread
or the timer beforehand or does .net cleanup and sort things for you ?

thanks
Peted
Mar 21 '07 #1
5 3234
>1. in a MDI app if you have multiple child forms, does each child
>form run in its own thread ? Eg do you get error trying to update one
control on form1 from form 2
No

>2. if you have a timer control running on a childform, and you either
a. minimize or

b. hide the form or

c. the form is no longer the currently selected form ,
does the timer keep running or does it stop ?
It keeps running.

>3. if you have a timer or a thread running on a child form, and you
close the form or end the application, do you have to stop the thread
or the timer beforehand or does .net cleanup and sort things for you ?
You may have to stop the thread (if it's not marked as a background
thread). You probably don't have to stop the timer, but it certainly
doesn't hurt doing so.
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Mar 21 '07 #2
<Petedwrote:
Just some threading questions

1. in a MDI app if you have multiple child forms, does each child
form run in its own thread ? Eg do you get error trying to update one
control on form1 from form 2
No, unless you've specifically put them in different threads, they'll
be in their own thread.
2. if you have a timer control running on a childform, and you either
a. minimize or

b. hide the form or

c. the form is no longer the currently selected form ,

does the timer keep running or does it stop ?
I believe it keeps running (it would be odd not to) - but that's easy
for you to test.
3. if you have a timer or a thread running on a child form, and you
close the form or end the application, do you have to stop the thread
or the timer beforehand or does .net cleanup and sort things for you ?
The timer will be disposed automatically, and even if somehow it isn't,
it isn't running in a separate foreground thread anyway, so you don't
need to worry.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 21 '07 #3
"Peted" wrote in message news:j5********************************@4ax.com...
1. in a MDI app if you have multiple child forms, does each child
form run in its own thread ? Eg do you get error trying to update one
control on form1 from form 2
They al use the same thread. No problem updating one child form from
another.
2. if you have a timer control running on a childform, and you either
a. minimize or
b. hide the form or
c. the form is no longer the currently selected form ,
does the timer keep running or does it stop ?
It keeps running.
3. if you have a timer or a thread running on a child form, and you
close the form or end the application, do you have to stop the thread
or the timer beforehand or does .net cleanup and sort things for you ?
It depends on how you start the Thread. If you set the IsBackground
property of the thread object to true, then the thread is automatically
stoped when you stop the main program. Otherwise, you have to be careful,
because the thread will continue to run in the background even if you close
all visible forms. No such problem with the Timer Control, which is Disposed
when the form that contains it is Disposed.

Mar 21 '07 #4
<Petedwrote:

<snip>
3. if you have a timer or a thread running on a child form, and you
close the form or end the application, do you have to stop the thread
or the timer beforehand or does .net cleanup and sort things for you ?
Sorry, I only addressed this from the point of view of a WinForms
timer. If you've created a separate thread, and haven't set
IsBackground to true, you'll need to stop the thread.

See http://pobox.com/~skeet/csharp/threads/shutdown.shtml for a pattern
of terminating threads cleanly.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 21 '07 #5
thanks for all those responses
cheers


On Wed, 21 Mar 2007 15:25:40 +0800, Peted wrote:
>Just some threading questions
1. in a MDI app if you have multiple child forms, does each child
form run in its own thread ? Eg do you get error trying to update one
control on form1 from form 2

2. if you have a timer control running on a childform, and you either
a. minimize or

b. hide the form or

c. the form is no longer the currently selected form ,
does the timer keep running or does it stop ?

3. if you have a timer or a thread running on a child form, and you
close the form or end the application, do you have to stop the thread
or the timer beforehand or does .net cleanup and sort things for you ?

thanks
Peted
Mar 21 '07 #6

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

Similar topics

19
by: Jane Austine | last post by:
As far as I know python's threading module models after Java's. However, I can't find something equivalent to Java's interrupt and isInterrupted methods, along with InterruptedException....
8
by: Z D | last post by:
Hello, I'm having a strange problem that is probably due to my lack of understanding of how threading & COM Interop works in a WinForms.NET application. Here's the situation: I have a 3rd...
6
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a...
10
by: Bob | last post by:
Okay, I've done this for years but now I'm going to question it just because this idea has been at the back of my head since I started using DotNet... My WinForms app queries a database every 60...
2
by: KSC | last post by:
Hello, I have used a thread timer as in the documentation on MSDN in my VB.NET application. Using System.Threading.Interlocked.Increment I increment the counter to a certain point, perform an...
8
by: bob | last post by:
I am unsure how to approach a C# windows App. Essentially I want to do this. I want to write an app that reads from database_A performs some calculations updates the pretty dials on the screen...
4
by: Giovanni | last post by:
Hi All, I need help with the following: Using VB.NET 2005, I am building a custom class in a separate assembly. The purpose of this class is to poll the internet to determine connectivity. I...
8
by: WhiteWizard | last post by:
I guess it's my turn to ASK a question ;) Briefly my problem: I am developing a Windows app that has several User Controls. On one of these controls, I am copying/processing some rather large...
5
by: CCLeasing | last post by:
For an application I'm creating I want to create a 'fake' progress bar. By fake I mean a progress bar that looks like it's doing something but actually isn't. I know philosophically this isn't...
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:
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.