dcsimg
Results 1 to 2 of 2

Thread: BackGroundWorker and System.ComponentModel

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2009
    Posts
    415

    BackGroundWorker and System.ComponentModel

    Project with 10 Forms.

    The Main Form has 3 BackGroundWorkers, while other 4 Forms have a single one.

    If I don't import in the Main Form "System.ComponentModel" I get lots of errors like:

    BC30002- Type 'DoWorkEventArgs' not defined.
    BC31029- The 'BW_Wheel_DoWork' method cannot handle the 'DoWork' event because it does not have a compatible signature.

    In the other forms BackGroundWorkers works without error even if I DON'T import System.ComponentModel (and if I import it the writing becomes light gray (not necessary)).

    Why??
    Last edited by phil2000; Apr 16th, 2019 at 04:19 PM.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,250

    Re: BackGroundWorker and System.ComponentModel

    Whenever you use ANY type in code, you need to specify the namespace it is a member of. That's because the compiler MUST be able to unambiguously identify what type you are referring to in order to know whether you can use it the way you are. In a VB.NET project, there are three ways to do this:

    1. Qualify the type name with the namespace name in code where you use it.
    2. Import the namespace at the top of the file in which the type is used.
    3. Import the namespace in the project properties.

    It is also possible to combine 1 with 2 or 3, i.e. import part of the namespace and then qualify the type name with the rest.

    The fact that you cannot use those type names unqualified in one of your forms indicates that you have not imported that namespace at the project level. If you are using the same namespace in multiple code files then you should do that. You do so on the References page of the project properties.

    If you don't have to import the namespace in other files that use member types then that suggests that those member types are already fully qualified where they are used. If you, for instance, double-clicked a BackgroundWorker in the designer to generate a DoWork event handler, I think you'll find that the generated code does indeed fully qualify the DoWorkEventArgs type, although I haven't confirmed that. Perhaps your other code that doesn;t do so was copied from another source.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width