Basic questions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • p988

    #1

    Basic questions

    Someone said that: [STAThread]/[MTAThread] in Main() only effect when
    dealing with COM interop in console type application." Is this correct?

    What if calling a regular DLL coded in C, instead of a COM object, is this
    attribute still necessary?

    Under what conditions should "[MTAThread]" be used instead of "[STAThread]"?
    When to use "[STAThread]" then?



    In a C#'s .cs file, a class is derived as ((1), (2) and (3) are added for
    explanation):

    public (1) class BaseForm : (2) Form
    {
    (3) string myString = " Hello, world!";

    public BaseForm(){
    ...
    }
    ...
    }

    What's the default modifier above before "Form" at place (2)and (3)?
    Why "public" is used at (1)? If missing what's the default modifier at (1)?


    Thanks in advance!



  • Klaus H. Probst

    #2
    Re: Basic questions


    "p988" <p988@hotmail.c om> wrote in message
    news:%23hY2rpVs DHA.2440@TK2MSF TNGP12.phx.gbl. ..[color=blue]
    > Someone said that: [STAThread]/[MTAThread] in Main() only effect when
    > dealing with COM interop in console type application." Is this correct?[/color]

    Yes. Further, it's only "locked" after the first call to unmanaged code. You
    can set the ApartmentState property of the current thread to change it.
    [color=blue]
    > What if calling a regular DLL coded in C, instead of a COM object, is this
    > attribute still necessary?[/color]

    No.
    [color=blue]
    > Under what conditions should "[MTAThread]" be used instead of[/color]
    "[STAThread]"?[color=blue]
    > When to use "[STAThread]" then?[/color]

    Depends on what type of COM server you're talking to, or writing. In general
    MTA should be used, but there's no "hard" rule.
    [color=blue]
    > public (1) class BaseForm : (2) Form
    > {
    > (3) string myString = " Hello, world!";
    >
    > public BaseForm(){
    > ...
    > }
    > ...
    > }
    >
    > What's the default modifier above before "Form" at place (2)and (3)?
    > Why "public" is used at (1)? If missing what's the default modifier at[/color]
    (1)?

    Inheritance is always public in C# (unlike C++ where it can be private), so
    (2) implies public. (3) is private by default. (1) is internal (to the
    containing assembly) by default, IIRC.

    --
    _______________ _____
    Klaus H. Probst, MVP
    http://www.vbbox.com/


    Comment

    Working...