object reference not set to an instance of an object

D

Dakkar

I have a code like this

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
using System.Data.Odbc;
using System.Text;
using System.Data;
using Microsoft.Win32;
using System.IO;
using System.Diagnostics;
using System.Net;



public class sylagent : Form
{
private Process[] myproc;
private Timer t1;
private FileVersionInfo myinfo;
private int count;
private System.ComponentModel.Container components = null;
private String program;

public sylagent()
{
myproc = Process.GetProcesses();
count = 0;
this.Size = new Size(300, 300);
this.Location = new Point(100, 100);
this.Visible = false;

this.t1 = new Timer();
this.t1.Interval = 1000;
this.t1.Start();
this.t1.Tick += new EventHandler(t1_tick);

}

protected override void Dispose(bool Disposing)
{
if (Disposing)
{
if (components != null)
{
components.Dispose();
}
}
Process[] procuo = Process.GetProcesses();
for (int i = 0; i < procuo.Length; i++)
{
if
(procuo.ProcessName.Equals("client"))
{
procuo.Kill();
}
}

base.Dispose(true);

}

public void t1_tick(object sender, EventArgs e)
{
for (int i = 0; i < myproc.Length; i++)
{
if (this.myproc.MainModule.FileName !=
null)
{
this.program =
this.myproc.MainModule.FileName.ToString();
}

if (this.program[0] == 'C' ||
this.program[0] == 'D' || this.program[0] == 'E' ||
this.program[0] == 'F' || this.program[0] ==
'G')
{
this.myinfo =
FileVersionInfo.GetVersionInfo(this.myproc.MainModule.FileName.ToString());
}

if
(this.myinfo.OriginalFilename.ToString().Equals("connector.exe"))
{
this.count++;
}

}
if (this.count != 1)
{
this.Close();
}
this.count = 0;

}

public static void Main()
{
Application.Run(new sylagent());

}
}


and when i execute my program i m taking this error
[code:1:dcfdf8a81c]
object reference not set to an instance of an object
[/code:1:dcfdf8a81c]

How can i fix it
Thanks
 
N

NeoNet

"Dakkar" <[email protected]> ha scritto nel
messaggio
and when i execute my program i m taking this error
[code:1:dcfdf8a81c]
object reference not set to an instance of an object
[/code:1:dcfdf8a81c]
Where?

How can i fix it

set the object to an istance :)
 
D

Dakkar

Its not showing the line

how can i instance the object
NeoNetwrote:
Dakkar said:
messaggio

and when i execute my program i m taking this error

object reference not set to an instance of an object

Where?

How can i fix it
set the object to an istance :)
 
N

Nick Malik [Microsoft]

put in a try-catch block. In the catch statement, write out the exception as
Console.WriteLine(exc.ToString())

When you do this, you get a complete dump of the location of the error.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
 
R

Registered User

Why does the timer's event handler rely on the Process[] myproc
created in the c'tor while the Dispose method creates its own
Process[]?

<HelpFile>
GetProcess - Overloaded. Creates an array of new Process components
and associates them with existing process resources.
</HelpFile>

If an existing process is killed, its associated component in the
array will still exist. The array element will have an object
reference set to an object that no longer exists.

regards
A.G.

On 19 Feb 2005 09:42:28 -0600,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top