:: Home

  login:         
  passwords:  

Winforms Interview Questions

Windows Forms Deployment
Windows Forms Controls
Windows Forms Data Binding
Windows Forms Datagrid
Windows Forms Docking
Windows Forms Keyboard Handling
Windows Forms Layout
Windows Forms Licensing
Windows Forms Menus
Windows Forms Mouse Handling
Windows Forms from MFC
Windows Forms from VB6
Windows Forms Patterns
Windows Forms Printing
Windows Forms Resources
Windows Form Scrolling
Windows Forms Tips
Windows Forms Common Dialogs
Windows Forms Listbox
Windows Forms ComboBox
Windows Forms Rich TextBox
Windows Forms ListView
Windows Forms TreeView
Windows Forms Button
Windows Forms TabControl
Windows Forms TextBox
Windows Forms MDI
Windows Forms Cursors
Windows Forms WebBrowser
Windows Forms PictureBox
Windows Forms Form
Windows Forms MDI
Windows Forms In IE
GDI+Bitmaps&Images
GDI+Font
GDI+Color
GDI+Brushes
GDI Drawing Tips
GDI+ from GDI
GDI Paths Regions
GDI+Pens
Interioerability WIn32
Tools Metadata Viewers
Design Time Serialization
Design Time Custom Designers
Design Time Tips
Design Time Type Editors
Vs.Net Tips
Vs.Net Debugging
Vs.Net Macros
Framework Tips General
Framework Tips Events
Framework Tips General IO
Framework Tips Strings
Framework Tips Threading
Tool Resource Editor
Design Time UI
Framework Tips CGI
Framework Tips XML

WPF Interview Qs

SilverLight Interview Qs

SAP Interview Questions

Oracle Interview Questions

PHP Interview Questions

Ajax Interview Questions

IIS 7.0

OOP Interview Questions

Ruby Interview Questions

Sql Server Interview Questions

SharePoint 2007 Questions

Microsoft Crm Questions

Framework Tips Threading

The General Winforms Interview Questions consists the most frequently asked questions in Winforms. This list of 100+ questions guage your familiarity with the Winforms platform. The q&a have been collected over a period of time from various blogs, forums and other similar Winforms sites

54. Framework Tips Threading

    54.1 Why do I have to use the STAThread attribute for my main method in my app.?
    54.2 When I close my application, my secondary thread does not exit.
    54.3 I call invoke Abort on my threads, but they still do not terminate.

54.1 Why do I have to use the STAThread attribute for my main method in my app.?


While the STAThread is required (as the documentation states) and pertinent only to applications that use COM interop, 1.0 version of the .Net framework has some bugs that makes it necessary for you to specify the STAThread attribute:
1) Ole Drag Drop will not work without STA. You can check this by turning on drag and drop in a form and try to run it.
2) Invoking a method in a type using Reflection will not work either.
These bugs have however been resolved in the 1.1 version of the framework (Everett). Which means you then do not have to specify this attribute for your main method.


54.2 When I close my application, my secondary thread does not exit.

In most cases, this can be resolved by making the thread a background thread through it's IsBackground property.
By default, managed threads are created as foreground threads, while unmanaged threads are created as background threads. When all of the foreground threads in an application have terminated, the CLR invokes Abort on the background threads that are still running.


54.3 I call invoke Abort on my threads, but they still do not terminate.

There are several possible reasons for this.

Invoking Abort on a suspended thread will have no effect until the thread is resumed. Once it is resumed, then the Abort will be carried out.


Also, when closing your application, you can make sure that the secondary threads are terminated by calling Join (myWorkerThread.Join) immediately after invoking Abort on the thread. For instance, this would be necessary if the thread is in the middle of an intensive operation, or even if it is simply sleeping.

Copyright 2007, Megasolutions Ltd