|
what is that?
and how to do it in c#?
any examples?
|
|
|
|
|
jrahma wrote: what is that?
Search the web for it, then you'll see what it is.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Good Afternoon All
I have a Windows Service and its Task is to kill a process. the Service is accepting the name of the Process through a Application.Config file. The Service does not Kill the Process. Here is a code that kills the Process as long as the Process is running
namespace Process_Killer
{
public partial class Process_Killer : ServiceBase
{
public Process_Killer()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
String Process_Kill = ConfigurationSettings.AppSettings.Get("Process");
FindAndKillProcess("Process_Kill");
}
protected override void OnStop()
{
}
public void FindAndKillProcess(String name)
{
Process[] procList = Process.GetProcessesByName(name);
while (procList.Length > 0)
{
procList[0].Kill();
}
}
}
}
What is Wrong ?
What is Wrong ?
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
Killing a process using a service sounds a little bit odd/risky.
However, if there's no error, the first thing I would do is to check that procList.Length is at least 1 when you expect to find a process. Writing to a log file would be an easy way since service may not communicate with desktop.
Also surround your code in OnStart method using try block and in catch write any problems to the same log file.
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
Good Morning Sirs
The Problem was the Variable, it was in Quotes, after that it, worked , but it will kill only one Process. at that moment. i want it to Kills all the Processes with that same name and Sleep for 10 min and wakeup again and kill again. Here is the Changed code
namespace Process_Killer
{
public partial class Process_Killer : ServiceBase
{
String Process_Kill = ConfigurationSettings.AppSettings.Get("Process");
public Process_Killer()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
FindAndKillProcess(Process_Kill);
}
protected override void OnStop()
{
}
public void FindAndKillProcess(String name)
{
Process[] procList = Process.GetProcessesByName(name);
if (procList.Length > 0)
{
procList[0].Kill();
}
}
}
}
Thank you
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
Your code makes no sense as a service.
You only attempt to find and kill the process once when the service starts,
then you do nothing except loop endlessly trying to kill the same process
over and over again (and consuming pretty much all the CPU cycles for a processor).
What if there's more than one process of the same name running?
Not returning from OnStart() prevents the service from starting.
If you intend your service to stay running and watch for that process and kill it,
you need to start a thread to do that. You can start the thread in OnStart().
You also need to kill ALL the processes in the procList then reload the procList
to check for new instances. You should also sleep a bit in that loop if you're going to
use a loop like that.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thank you for your Answer, How can i Archive that, because that is exactly what i want. can you please refer me to an article or give me an example.
Thank you
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
Thank you for your Reply i have Found a Solution .i did it like this
protected override void OnStart(string[] args)
{
String Process_Kill = ConfigurationSettings.AppSettings.Get("Process");
Thread thread = new Thread(new ParameterizedThreadStart(DoWork));
thread.Start(Process_Kill);
}
public void DoWork(object data)
{
string Process_Kill = data.ToString();
while (true)
{
FindAndKillProcess(Process_Kill);
Thread.Sleep(5000);
}
}
public void FindAndKillProcess(String name)
{
Process[] procList = Process.GetProcessesByName(name);
for (int i = procList.Length - 1; i >= 0; i--)
{
procList[i].Kill();
}
}
Thank you
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
That looks much better
Thanks for the update.
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I'm writing a service that connects to oracle and I can't retrieve any data. I am using the System.Data.OracleClient namespace to do this. Is there some sort of caching that I should know about or something else that can cause this???
|
|
|
|
|
Stephen Lintott wrote: and I can't retrieve any data.
If there is a problem there should be some sort of error being returned, set, reported or something, that indicates what the problem is. Why have you not posted that here?
Stephen Lintott wrote: I'm writing a service that
There are two parts of a Service. One part is the code needed to interact as a Service to the OS. The other part is your project code. Did your project code get developed and tested running under a windows user desktop account before it was added to a Service?
led mike
|
|
|
|
|
Most likely the code isn't executed at all or you're hitting an error and ignoring it (if the service call doesn't fail). Try to gather more info what code is run or any error messages that may indicate the cause. Writing to a log file could be one way if you're unable to debug the service side.
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
I'm using the DataAdapter.Fill method in my code and thats working only the DataSet that is returned does not contain any data. I can see the data in toad but it doesn't come back using the connection objects. No errors are thrown please help...
Stephen Lintott Bsc IT (RAU)
|
|
|
|
|
You should try to get more information about the problem. With the info you supplied, I'm merely guessing.
Check these things:
- if you're using parameters in your query, check their values before execution
- also take the executed sql, place the parameter values to it and use that in toad, just to make sure that query is the same you tested
- after DataAdapter.Fill, write somewhere how many rows was returned to make sure that the dataset is really empty and you are not for example returning a copy of the dataset etc
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
Hi ALL,
how to work with confidence level & threshold value while work with Speech API 5.1 in windows xp to increase accuracy of speech recognition.
|
|
|
|
|
I am trying to refer some code at
http://mokhan.ca/blog/2007/09/25/SALES+TAXES.aspx[^]
I couldnt understand the use of delegates as below:
private double CalculateAmount( ) {
double amount = 0d;
Summary( delegate( ITax tax ) { amount += tax.Amount; } );
return amount;
}
How and why its being used here????
~AHAGeek
|
|
|
|
|
Summary takes a delegate to calculate tax, however, the Summary method seems out of place since there is nothing to provide a return value to amount meaning the only possible action the summary method can perform is to sum all of the applied taxes.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
they are in a different class named baglanti
public GroupBox gb;
public void gbColor(GroupBox gbT)
{
gb = gbT;
gb.MouseClick += new MouseEventHandler(gb_click);
}
private void gb_click(object sender, EventArgs e)
{
gb.BackColor = Color.Red;
}
in other class i use this to add gb_click event to the groupboxes
clsBgl.gbColor(groupBox1);
clsBgl.gbColor(groupBox2);
clsBgl.gbColor(groupBox3);
it always execute the lastone, when i click on groupbox3 its color is changing but others stay same.
thanx for your helps..
thanks for everything i have...
|
|
|
|
|
TALHAKOSEN wrote: clsBgl.gbColor(groupBox1);
clsBgl.gbColor(groupBox2);
clsBgl.gbColor(groupBox3);
you are overwriting the variable (gb) so the behavior is expected
instead create a new instance of the class for every groupbox
gb1 = new clsgbl
gb1.gbcolor(groupbox1)
gb2 = new clsgbl
gb2.gbcolor(groupbox2)
gb3 = new clsgbl
gb3.gbcolor(groupbox3)
(not shure about the syntax been a while since I done c#)
|
|
|
|
|
Thx for your help and i found how to to do that exactly
public void gbRenk( GroupBox gb)
{
gb.MouseClick += new MouseEventHandler(gb_renkAl);
}
private void gb_renkAl(object sender, EventArgs e)
{
((GroupBox)sender).BackColor = Color.Red;
}
thanks for everything i have...
|
|
|
|
|
I want to upload a textfile created in my server to an ftp server thru C#.net code or FtpWebRequest.........
|
|
|
|
|
is the destination folder is a share folder or network mapped folder??
|
|
|
|
|
Hi,
I have the following scenario for a social networking site I am working on.
Users create accounts in the site and then can edit their details etc. They can also have their public facing page (which will be seen by others when they click on their name etc).
Example User A signs up and then creates his public page e.g. site.aspx
I want that the user can customise this page using webparts and .net personalisation so that his changes made (like themes or webparts) can be seen by User B.
I first got it working by letting the user modify his own page but the changes reflected only when he logged on.
Then I got it working by using the following:
<webParts>
<personalization>
<authorization>
<allow users="*"
verbs="enterSharedScope"/>
</authorization>
</personalization>
</webParts>
However, with the second approach now anyone could edit his page and save the shared view as all users will have permissions to amed their pages.
I am trying a third solution by creating folders for users and then copying a default.aspx and web.config file in it, thinking there may be a way this way... but am stuck.
The users are created using asp.net membership with additional details held in custom table.
Any ideas on how to implement this functionality of user customisable page where customisations can be seen by others as well as him.
Thanks,
Adeel
|
|
|
|
|
I have started a thread in the SQL Forum asking about experiences others have had using CLR-based SPs in SQL Server. Rather than do a complete cross-post and end up with two threads, I would like to ask any C# developers here that have something to offer to the discussion to please go over there and contribute:
http://www.codeproject.com/script/Forums/View.aspx?fid=1725&msg=2777359[^]
Thanks!
Peace!
-=- James Please rate this message - let me know if I helped or not!<hr></hr> If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! See DeleteFXPFiles
|
|
|
|
|
Hay ..
I have a table for eg , emp with the next data :
ID Name
1 AA
2 BB
3 CC
I fill the combo box as the next :
<br />
combobox.ValueMember=ID;<br />
combobox.DisplayMember = Name;
the user see Name but the application save ID in the database .
then when I navigate records , sure the combobox dispaly the ID which is saved on database ,,
I tried to do that :
combobox.SelectedValue = combobox.Text;
but it didn't give me the required result..
I want to view the Value (Name field) instead of text (ID field)
thanks
jooooo
|
|
|
|