473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to fix Exception "object reference not set to an instance of anobject"

Hi all,

I am coding for displaying a splash screen until a big job is
finished.I am getting an exception:only during the first start of the
system.Rest all the time

it is working fine.

Only when i restart the PC my application will be launced by windows
services at startup and i get the exception saying:

"Object reference not set to an instance of an object" please see
Problem:- to see where i am struck

And the splash screen once stated displaying it will not close even
though the big process has completed.i have to stop and restart the
service and then the

splash screen works fine.

Algorithm:
----------

StartSplash(no interaction by the user only function calls)

//long process which may take from 5 secs upto 2 min upto that time
splash screen will be displayed

stopsplash(no interaction by the user only function calls)
//file splash.cs
namespace rag
{
class splash
{
//Variables and handles
Thread th = null;

Splashevt SplashOpr = null;

// events used to stop worker thread
ManualResetEvent m_EventThreadStopped;

//Class constructor
public splash()
{
// initialize events for thread
m_EventThreadStopped = new ManualResetEvent(false);

}

public void StartSplash(String str)
{
//start a new thread to start the splash
th = new Thread(new ThreadStart(DoSplash));
th.Priority = ThreadPriority.Lowest;
th.IsBackground=true;
//start the thread
th.Start();
}
/// <summary>
/// Thread function to display the splash screen
/// </summary>
private void DoSplash()
{

int start = 1;
//send the controller number
SplashOpr = new Splashevt();
//Start the splash screen
SplashOpr.Run(start);
}

/// <summary>
/// To Stop the Flash Screen
/// </summary>
public void StopSplash()
{

int Stop = 2;

while (th.IsAlive)
{

Trace.Write("Inside While\n");
m_EventThreadStopped.Set();
if (WaitHandle.WaitAll(
(new ManualResetEvent[]
{ m_EventThreadStopped }),
100,
true))
{
Trace.Write("Inside thread event\n");
SplashOpr.Run(Stop);
break;
}
//process the messages
Application.DoEvents();
}
}

}
}

//file splashevt.cs

namespace rag
{
delegate void CloseSplashScreenDelegate();

/// <summary>
/// To stop the thread call the function of class Longprocess
/// </summary>
public class Splashevt
{
#region Members

Splash sp = null;
#endregion

#region Functions

public Splashevt()
{

}
public void Run(int splashstate)
{

//Start the Splash Screen
if (1 == splashstate)
{

sp = new Splash();

//Display the splash screen
sp.ShowDialog();

}
//Stop the splash screen
else if (2 == splashstate)
{
try
{
if (sp != null)
{
sp.Invoke(new
CloseSplashScreenDelegate(CloseSplashScreen));
}

}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Errorinstopsplash",
MessageBoxButtons.OK);

//problem:- First time i start the PC since my
application will be launched as a windows service
i get an exception saying :- "object reference not
set to an instance of an object".It is because sp is null
But iam calling everytime startsplash first then
stopsplash then why is this sp not having any vaue??

Once i stop the service and restart it again.it works
fine.only during the start of the PC it is null.

//can anyone please help on this thnx in advance---
raghu

}
}
}

private void CloseSplashScreen()
{
sp.Close();
}

#endregion
}
}
Oct 17 '08 #1
0 1962

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bob Cannistraci | last post by:
A three-tier user authentication system was running without a problem for almost a year and now is suddenly dysfunctional. We don't know of any changes to any of the servers. It's quite maddening....
1
by: Robert A Riedel | last post by:
I am completely baffled when the following managed exception is thrown: "Object reference not set to an instance of an object" from a nested subroutine when referencing a variable allocated on the...
1
by: Chris Magoun | last post by:
I suddenly received an unexpected error in my project. I have been working on this project for some time without this issue. Nothing has changed in the form that caused the exception. A little...
2
by: prince -=nore=- | last post by:
I have a page, where I'm retrieving a file location from a database and outputting it's contents (HTML) onto a web page. On the aspx page, I have referred to the code behind it using the line...
2
by: xhenxhe | last post by:
I don't some Excel automation. I've created a program that opens and Excel template and inputs information to it. It runs great on my machine. When I build and deploy I have a user that keep...
1
by: Gummy | last post by:
Hello, I've been banging my head against the wall for a few days on this. When I run a page, either in "View in Browser" or I actually build the solution, I occasionally and very randomly get...
2
by: louie.hutzel | last post by:
This JUST started happening, I don't remember changing any code: When I click the submit button on my form, stuff is supposed to happen (which it does correctly) and a result message is posted back...
0
by: Tamer Ibrahim | last post by:
Hi, Sometimes, I got the following error message when I use ajax calendar control on some aspx pages : Object reference not set to an instance of an object. Description: An unhandled exception...
1
by: atishrg | last post by:
Hello all, I am facing a problem,, that I am not able to trace a "OBJECT REFERENCE NOT SET TO AN INSTANCE OF AN OBJECT" EXCEPTION .... as I am using On error goto _Lable as soon as this...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.