Click here to Skip to main content
16,004,833 members
Home / Discussions / C#
   

C#

 
GeneralRe: File Format Pin
Luc Pattyn16-Sep-09 5:35
sitebuilderLuc Pattyn16-Sep-09 5:35 
QuestionNullReferenceException was unhandled Pin
Chantal Labrie16-Sep-09 3:27
Chantal Labrie16-Sep-09 3:27 
AnswerRe: NullReferenceException was unhandled Pin
Keith Barrow16-Sep-09 3:33
professionalKeith Barrow16-Sep-09 3:33 
AnswerRe: NullReferenceException was unhandled Pin
Luc Pattyn16-Sep-09 4:05
sitebuilderLuc Pattyn16-Sep-09 4:05 
AnswerRe: NullReferenceException was unhandled Pin
Muhammad Mazhar16-Sep-09 11:27
Muhammad Mazhar16-Sep-09 11:27 
QuestionAdd extension to X509Certificate Pin
Liborac_16-Sep-09 2:27
Liborac_16-Sep-09 2:27 
QuestionLong operation in c#, when does main end? Pin
yeah100016-Sep-09 2:15
yeah100016-Sep-09 2:15 
AnswerRe: Long operation in c#, when does main end? PinPopular
Luc Pattyn16-Sep-09 2:26
sitebuilderLuc Pattyn16-Sep-09 2:26 
Hi,

when your app starts, it has only one thread, the "main" or "GUI" thread. It gets more if and when you create them (Thread, ThreadPool, BackgroundWorker) or perform asynchronous I/O operations (e.g. SerialPort.DataReceived).

All GUI operations (including window moving and resizing) are handled on the main thread; that mainly consists of executing the event handlers you provide, such as Form_Load, Button_Click, and many others. The events that trigger them are collected in an "input queue" and executed one by one, so one handler has to finish before the next one can start; that is why a window won't move if it is in the middle of a lengthy operation inside say a Button_Click handler. With one exception: when Application.DoEvents() is called often enough, everything may appear to be running smoothly (in reality you are running a big risk of instability, one should avoid DoEvents most of the time).

To keep the GUI responsive one should limit the execution time of each handler to a small timespan, say 30 milliseconds. Anything that always or sometimes may take more should be delegated to another thtead; otherwise the user will dislike the way he looses control of the GUI.

And the main thread comes to an end when it has no more work to execute, that typically happens when the main form gets closed causing the Application.Run() method to return in the static Main() method (inside file Program.cs); unless you started some threads that still haven't finished executing their code and didn't get marked with IsBackground=true.

Smile | :)

Luc Pattyn

Have a look at my entry for the lean-and-mean competition; please provide comments, feedback, discussion, and don’t forget to vote for it! Thank you.

Local announcement (Antwerp region): Lange Wapper? Neen!


GeneralRe: Long operation in c#, when does main end? Pin
Nagy Vilmos16-Sep-09 2:30
professionalNagy Vilmos16-Sep-09 2:30 
GeneralRe: Long operation in c#, when does main end? Pin
Luc Pattyn16-Sep-09 2:44
sitebuilderLuc Pattyn16-Sep-09 2:44 
GeneralRe: Long operation in c#, when does main end? Pin
musefan16-Sep-09 2:34
musefan16-Sep-09 2:34 
GeneralRe: Long operation in c#, when does main end? Pin
Luc Pattyn16-Sep-09 2:46
sitebuilderLuc Pattyn16-Sep-09 2:46 
GeneralRe: Long operation in c#, when does main end? Pin
musefan16-Sep-09 2:58
musefan16-Sep-09 2:58 
GeneralRe: Long operation in c#, when does main end? Pin
Luc Pattyn16-Sep-09 2:59
sitebuilderLuc Pattyn16-Sep-09 2:59 
GeneralRe: Long operation in c#, when does main end? Pin
musefan16-Sep-09 3:19
musefan16-Sep-09 3:19 
GeneralRe: Long operation in c#, when does main end? Pin
harold aptroot16-Sep-09 2:38
harold aptroot16-Sep-09 2:38 
GeneralRe: Long operation in c#, when does main end? Pin
Nuri Ismail16-Sep-09 2:40
Nuri Ismail16-Sep-09 2:40 
GeneralRe: Long operation in c#, when does main end? Pin
yeah100016-Sep-09 2:48
yeah100016-Sep-09 2:48 
GeneralRe: Long operation in c#, when does main end? Pin
dan!sh 16-Sep-09 3:07
professional dan!sh 16-Sep-09 3:07 
GeneralRe: Long operation in c#, when does main end? Pin
musefan16-Sep-09 3:20
musefan16-Sep-09 3:20 
GeneralRe: Long operation in c#, when does main end? Pin
Luc Pattyn16-Sep-09 3:22
sitebuilderLuc Pattyn16-Sep-09 3:22 
GeneralRe: Long operation in c#, when does main end? Pin
Luc Pattyn16-Sep-09 3:40
sitebuilderLuc Pattyn16-Sep-09 3:40 
GeneralRe: Long operation in c#, when does main end? Pin
N a v a n e e t h16-Sep-09 3:33
N a v a n e e t h16-Sep-09 3:33 
GeneralRe: Long operation in c#, when does main end? Pin
Luc Pattyn16-Sep-09 3:41
sitebuilderLuc Pattyn16-Sep-09 3:41 
GeneralRe: Long operation in c#, when does main end? Pin
DaveyM6916-Sep-09 3:44
professionalDaveyM6916-Sep-09 3:44 

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.