|
Wow. Where to begin...
First, you've put this in the the OnStart procedure of your service. This means that it will only run ONCE per start of the service or on startup of Windows. OnStart is meant for you to start your service code, possibly on another thread. The way you have it setup, your code will execute once, then stop.
The error comes up because you have a problem with your code in the OnStart() method. You've got ALOT of problems with this code.
protected override void OnStart(string[] args)
{
Process[] aProcesses1;
if (aProcesses1.Length > 0)
{
if(rd1==true)
{
aProcesses1[aProcesses1.Length-1].Kill();
rd1=false;
}
}
int intExcelPID;
aProcesses1=Process.GetProcessesByName("man");
string strProc="These are the processes running \n";
for (int i = 0; i <= aProcesses1.GetUpperBound(0); i++)
{
intExcelPID = aProcesses1[i].Id;
strProc+=intExcelPID.ToString()+ " ";
}
RegistryKey hklm=Registry.LocalMachine;
hklm=hklm.OpenSubKey("SOFTWARE\\man");
Object obp=hklm.GetValue("Path");
string file=obp.ToString() + "\\man.exe";
Process.Start(@file);
}
But first, I take it your trying to find Excel processes that are left open by an application? Why?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hi all, I am new in C#.
I have two classes, class A and class B. Class B is inherited from class A.
When I create an object of class B, will an object of class A also be created?
In addition, if class A has a member "public string myName", after I create an object of class B, the created instance also can access myName, but what does the statement " base.myName = "HELLO" " mean? I know it assign "myName" of the base class (class A) with "HELLO", but why do we assign member of the base class if no instance of the base class created?
Regards,
Tommy
|
|
|
|
|
When you create an instance of a derived class, an instance of the base class (usually embedded in the instance of the derived class) is automatically created for you. That answers your second question as well, there is an instance of the base class.
You can usually get away without using the base prefix, as public and protected members of the base class are accessible from the derived class directly. Usually, the base prefix is used to call the base class implementation from within overridden functions and to disambiguate functions and member variables.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Thanks for your answer~~~
I have some more questions.
1) When a member in the base class (class A) is declared as private (say "private int x"), will the instance of the derived class (class B) has a that private member? Is that an inherited class always inherits all members of the base class but cannot access the private members? (For example, in this case, class B also has "private int x", but cannot access "x" )?
2) When a method in the base class (class A) is overridden by the derived class (class B), is that the overridden version of the method be always called?
For example,
class A
{
public virtual void Test()
{
Console.WriteLine("This is A");
}
}
class B : A
{
public virtual void Test()
{
Console.WriteLine("This is B");
}
}
static void Main()
{
B b = new B(); A a = b;
b.Test();
a.Test();
}
The above code sample is copied from a book, but I am confused.....
I know the statement "b.Test()" will cause the output "This is B"
but how about "a.Test()", as a is referenced to the object of type B, which version of the method will be called?
What is meant by "A a = b"?
Again, thanks a lot for your help!!
Regards,
Tommy
|
|
|
|
|
Hi, I'm trying to find out where the root path (ie. the physical folder of "http://mydomain.com/") is programmatically, but I'm not sure how to do this. After researching a bit, I came up with the following information:-
- In Wise Installer and Install Shield they check for the registry value under
HKLM\Software\Microsoft\InetStp\PathWWWRoot , but this only points to the default folder at installation, not the current (possibly moved) folder location. - In Windows XP, I'm able to find the correct location under
HKLM\System\CurrentControlSet\Services\W3SVC\Parameters\Virtual Roots , but this key does not exist in Windows 2003 Server operating system. In fact, on Windows 2003, I can't find the correct location anywhere in Registry! Is there a way to locate the right folder independent of any machine? - I know that in .NET it is possible to use
System.DirectoryServices.DirectoryEntry("IIS://mydomain.com/W3SVC") to locate the correct path, but I'm trying to find an easier way to do this - by using only files and registry. Using DirectoryEntry to query the IIS service may also result in a permission denied problem.
What I'm trying to do is to build a setup package in Install Shield to deploy a web-application. Since Install Shield can't locate the IIS root path correctly, I have to manually set the path myself. The capability of the Install-Script that comes with Install-Shield is limited, therefore I cannot use the third option above.
So can anyone shed a light here? Thanks in advance!
> whoami
The system is unable to identify you when you don't even know your name!
|
|
|
|
|
I would have the person manually set the path for your app, as they may have their server set up where the server has the files on a remote computer.
|
|
|
|
|
I am lookinf for a way to insert data into Field codes in Ms Word from C#, I have been able to get it to open up the template and insert the data but i cant find anyway to insert it at the point where the codes are (it just places the text at the top)
Anybody know of a way to reference the Fields?
Cheers
|
|
|
|
|
how about invoking the find & replace method.
|
|
|
|
|
Hi! Im trying to create a form with a button that saves the output as a "text" file. My problem is that this code compiles without any exceptions however it tends to hang at runtime. Can someone please tell me what is wrong with my code and if i'm missing anything. The output is bound to a grid and shows a couple of data based on my drop down list.
private void btnSave_Click(object sender, System.EventArgs e)
{
OdbcConnection cnn = new OdbcConnection();
cnn.Open();
OdbcCommand cmmd = new OdbcCommand();
OdbcDataAdapter adp = new OdbcDataAdapter (cmmd);
DataTable dt_emp = new DataTable();
adp.Fill(dt_emp);
System.Text.StringBuilder sb = new System.Text.StringBuilder();
for(int i=0;i<=dt_emp.Rows.Count - 1; i++)
{
for(int q=0;q<=dt_emp.Columns.Count - 1; q++)
{
sb.Append(dt_emp.Rows[i][q].ToString());
}
sb.Append(" ");
}
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=*.txt");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.text";
System.IO.StringWriter strWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new System.Web.UI.HtmlTextWriter(strWrite);
Response.Write(sb.ToString());
}
dt_emp is the data passed. Thanx in advance for all your replies!!!
|
|
|
|
|
Have you put in a break point to see if it's just working ? How many rows/columns are we talking here ?
tatchung wrote:
i<=dt_emp.Rows.Count - 1
i < dt_emp.Rows.Count is surely more readable ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
yeah i did and it passes right by the whole function. i'm sure there's something wrong with it but i just can't figure out what. rows = depends on the result columns = 5 (but i still have to add 3-5 more columns; i cut the columns down just to see if it'll work. i'm just starting to learn c# by the way and all your comments, suggestions and even violent reactions could be of great help to me
thanx for all your replies!
|
|
|
|
|
tatchung wrote:
yeah i did and it passes right by the whole function.
Do you mean the click event does not fire, or do you mean that the rows/columns are 0 and so the loop is skipped ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
the click does not fire. it hangs at runtime. did i miss anything in my code or do you think its in the query to the database?
thanx
|
|
|
|
|
So where does it hang then ? If the click event does not fire, where does it go and hang ?
You need to set this function as the click event for your button in the aspx.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
i did actualy. sori beating around the bush...whenever i click the save button the status bar on my browser hangs at 3 bars! it doesnt show anything at all and whats worse, my browser (internet explorer) crashes after a minute of hang time. dang i'm lost! that's what you get when newbies try out advanced stuffs. but i do appreciate your help! thanx a lot
thanx
|
|
|
|
|
OK - you've not done what I asked you then. If you're in debug mode, you can set a break point by placing the cursor on a line of code, and pressing F9. You can also right click and choose 'insert breakpoint'. Now your code will stop execution at this point, and you can view the state of variables, step through code, etc. The window to check variable state is on the bottom left, and you can use function keys or the Debug menu to step through. Now please do that, and check what values are being found, and why the loop is obviously not ending.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanx for the tutorial Chris! I hope Im not taking too much of your time. Well anyways I did what you told me to do and it stops at the 5th line of the code I posted; right on the cnn.Open(); . Now obviously the error is on the codes below it though how do i know what line needs to be fixed. I find my code logical...what do you think Chris?
thanx
|
|
|
|
|
Crap - how did I miss that ?
Yeah - debugging is great, especially at just working out exactly where the problem is.
The problem in this case is that you're not specifying a connection string, and so the connection object does not know what to connect to. I'm surprised it does not throw an exception, but it's obviously in the process of timing out, in utter confusion.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
isnt the OdbcConnection cnn = new OdbcConnection(); a connection string? im really sori if i sound too elementary to you guys. i learn fast though
thanx
|
|
|
|
|
No, a connection string is a text string that specifies the type of database, where it is, what it's called and how to connect to it. Your code is creating a new instance of a class used to connect to a database, but it does not know what database to connect to. What database are you using ? I suggest a google on OdbcConnection, assuming that you've got a database set up and ready to connect to. Also, if it's a SQL Server database, there are classes specifically for that ( although you still need a connection string ).
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
hey! thanx for your help! i was so frustrated with the code i forgot that google IS our friend! i'l keep posting on inqueries again. thanx for all your help
thanx
|
|
|
|
|
|
What is you connection string?
... Or did you not have one??
> whoami
The system is unable to identify you when you don't even know your name!
|
|
|
|
|
He didn't have one the code he used is posted in a past relpy on this thread.
|
|
|
|
|
very perceptive expert but in case you didnt notice that was me (wowowee) who posted the previous code. and yeah i forgot to declare a connection string.
|
|
|
|