Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / September 2004

Tip: Looking for answers? Try searching our database.

NullReferenceException using static members in a multi-thread .exe

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RobyFerro - 06 Sep 2004 15:07 GMT
Using a class with static members in a multi-thread executable results in

'System.NullReferenceException' exception.
This happen only if the class is not initialized (calling any static member)
before

trheads start.
The exception is not throw if:
- If I invoke a static member in main before threads start.
- The class is included in the application project and I don't use an
external library.

Following there is a sample of a solution that have the problem.

All happen with: .Net Framework 1.1.4322, Windows 2000 SP4, Visual Studio
.Net 2003 7.1.3088.

Any help would be appreciated.

Thanks
Sherif ElMetainy - 07 Sep 2004 00:36 GMT
Hello

Are you using ThreadStatic attribute? If so, the variable may be initialized
in one thread, and not initialized in another thread.
You need to post short code that demonstrates your problem to help people
help you.

Best regards,
Sherif

> Using a class with static members in a multi-thread executable results in
>
[quoted text clipped - 16 lines]
>
> Thanks
RobyFerro - 07 Sep 2004 08:27 GMT
Hello,
In this case I don't need to use ThreadStatic attribute for the static
members.
The class is a helper class to retrieve a connection string from
configuration file (in the samples the connection string is a constant
string), so the connection string is the same for all threads.
Anyway I tested ThreadStatic attribute with a proper initialization member
(without using a constructor). I will use this method only if there's no
other way,

About the sample it is the result of a long test and I can't reduce anymore
(I need 2 project application+library, I need a OpenConnection function, a
constructor, ecc.).

Thanks
 RobyFerro

> Hello
>
[quoted text clipped - 27 lines]
> >
> > Thanks

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.