|
Neeraj Kr wrote: Exactly. This is what I want to achieve. This is a customer requirement.
This is a stupid customer requirement. Killing all processes will always restart the PC because you will be killing critical OS processes. (The only reason it doesn't when you run from inside visual studio is because VS is preventing your app from doing stupid things)
Tell your customer that they don't really want to do that. Ask them what they are trying to achieve by killing all processes.
Simon
|
|
|
|
|
ha ha ha. Actually they already have a third party tool which does the same thing, but does not restarts the system.
They actually want a proprietory product.
-----Have A Nice Day-----
|
|
|
|
|
What the third party app will be doing is only killing non-critical processes.
Find out the real requirements from your customer. They don't really want to kill all processes, because that will cause a system restart. Find out what they actually want.
I suspect they want something like, close all open applications. In which case, you need to find a way of only closing user apps and not just blindly killing all system processes.
You should probably be using process.Close() instead of kill. This gives the exiting processes a chance to clean up their data.
Either way, the important point here is to ask the client what they actually want and why they want to do it.
Simon
|
|
|
|
|
Simon Stevens wrote: To me it looks like your code is trying to kill all running processes except Explorer, SvcHost and your own app
Exactly. This is what I want to achieve. This is a customer requirement.
-----Have A Nice Day-----
|
|
|
|
|
Umh, killing svchost on Windows is never a good idea.
Besides that, why don't you call proces.ProcessName.ToUpper().ToString().Trim() just once for each process in the list? Also, comparing something not in uppercase to this string will always result in false , so the != comparison is pointless.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
yea, I know that killing the svchost on windows is not good that is why I have put a check on that. Though, I guess could have written one condition for one process and not three different.
What else do you suggest please.
The problem is that when I run the application from VS 2008, it runs fine, but when I run the exe, it reboots my system.
-----Have A Nice Day-----
|
|
|
|
|
Assuming it is related to your process stomping, put a confirm dialog ahead of each kill and wait a minute or so between each yes click. That'll let you know what process's death is taking the system down.
The requirement itself is a major WTF, there has to be a better way to accomplish whatever the clients actual objective is.
You know, every time I tried to win a bar-bet about being able to count to 1000 using my fingers I always got punched out when I reached 4....
-- El Corazon
|
|
|
|
|
Let me just try that. Though I tried to put a MessageBox, but that was of no help.
-----Have A Nice Day-----
|
|
|
|
|
Greeeg wrote: proces.ProcessName.ToUpper().ToString().Trim() just once for each process in the list
Thats exactly what I meant when I said
Neeraj Kr wrote:
proces.ProcessName.ToLower().ToString().Trim() != "svchost" && proces.ProcessName.ToUpper().ToString().Trim() != "SVCHOST" && proces.ProcessName.ToString().Trim() != "SvcHost")
all do the same thing - you only need one of them
And it seems to me that anything other than those in his list will be killed, hence the system reboot.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Ashfield wrote: And it seems to me that anything other than those in his list will be killed
Which specific process causes the system to reboot apart from the SVCHOST. We can restrict the same.
-----Have A Nice Day-----
|
|
|
|
|
Countless ones! wininit.exe for example, winlogin too, csrss, services (and a host of services required under that).
Open you Task Manager, and start killing them and you will see. If you wanna do things in this retarded way, you will need to suffer the pain of debugging it.
|
|
|
|
|
Hi everyone,
I have a problem with executing some code in an Event.
In detail I use a WebBrowser control and its onDocumentCompleted Event.
When the Document is completely loaded I want to do some work (adding some event listeners to the document's mouse events).
But now, on pages containing frames, my event gets interrupted by the other frames firing the same event (I use the same method for every DocumentCompleted Event).
Does anyone know why my event gets interrupted and how I could manage to finish the event method and afterwards proceed it for the next event in queue?
Here is my code (the class ExtendedWebBrowser is inherited from the standard class WebBrowser):
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
MessageBox.Show("1");
ExtendedWebBrowser brws = ((ExtendedWebBrowser)sender);
brws.zoom = 3;
if (brws.Document.Window.Frames.Count > 0)
{
for (int i = 0; i < brws.Document.Window.Frames.Count; i++)
{
brws.Document.Window.Frames[i].Document.MouseMove += new HtmlElementEventHandler(tabControl_MouseMove);
brws.Document.Window.Frames[i].Document.MouseUp += new HtmlElementEventHandler(tabControl_MouseUp);
brws.Document.Window.Frames[i].Document.MouseDown += new HtmlElementEventHandler(tabControl_MouseDown);
}
}
brws.Document.MouseMove += new HtmlElementEventHandler(tabControl_MouseMove);
brws.Document.MouseUp += new HtmlElementEventHandler(tabControl_MouseUp);
brws.Document.MouseDown += new HtmlElementEventHandler(tabControl_MouseDown);
MessageBox.Show("2");
MessageBox.Show("3");
}
It would be fine if anybody could help me to solve the problem or give me a hint on how to search on (maybe I used the wrong words in google?!).
Maybe I have to say that I am more a novice in programming but willing to learn more
Thanks for your help.
Andreas
|
|
|
|
|
Member 4471292 wrote: Does anyone know why my event gets interrupted
Because you are showing a message box from the event handler.
Member 4471292 wrote: and how I could manage to finish the event method and afterwards proceed it for the next event in queue?
Don't use a message box in the event handler.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thank you for help.
I tried it out but the problem is not really fixed.
I have the same problem when putting break points instead of the MessageBoxes.
For the main page containing the frame set, all 3 break points are reached. But afterwards the event is called by the other frame pages and I reach only the first break point. Going through step-by-step I can see that the execution is interrupted by another document completed event.
Why does this happen? Where can I find a list or sth. else with all possible things which can interrupt an event?
My next problem is that the documentCompleted event is not fired when I reload the page via F5-Key. Can anyone say what I could do to catch this event, too?
Again big thx for your help.
Andreas
|
|
|
|
|
Hi,
I have a windows service (C#) running continously and so some values saving in memory always and at the time of stoping the service I need to save those values to an external file may be notepad etc. I am able to handle the stop event (OnStop) if it is a normal service stopping. But when the user is killing the process through task manager, I am unable to handle or track that event in my windows service, so that I cannot save the values from memory to the external file.
Is there any event provided by framework to handle those kind of killing process or is there any Win API providing those events to handle in windows service.
Anyone facing these situation please give me a response....Thanks in advance....
Do learnig to & from others....
Bins Davis
|
|
|
|
|
Handle the Application.ApplicationExit event.
Note that this will only get triggered if the user uses the "End Task" button on the Applications tab. The "End Process" button on the Processes tab will not trigger this event.
This is because EndTask allows the app to run any clean up code itself. EndProcess is to kill totally unresponsive processes. You can't get round this. You have to accept that the user always has overall control of their PC and if they want to kill your app without letting it clean up they can. Windows does warn that killing processes can cause undesired behaviour. (Just think, the user could just pull the plug out from the socket which would give your app no time to clean up)
I would suggest writing the data out periodically (say every 10 minutes) and save a timestamp with the data so you know when it was saved. Then, when the service is exited correctly, write out a little bit of information at the end of the file that says "Service exited correctly" or something that means that. Then, when your service starts up, look for the "Service exited correctly" message. If it's not there you know the service was terminated unexpectedly, so you can warn the user. If you stored a timestamp with the saved data you can tell the user how much data was lost etc.
Simon
|
|
|
|
|
Thanks for the response and help...
But I am still thinking that atleast operating system will get a notification that the said process is going to kill now or it is getting killed. So in that way, any API can provide those handling of killing. As you said saving data periodically will is one way we can achieve max data and if the EndProcess is having such a limitation, my requirement is still pariall.
So if you get further more info plese keep me posted....
Thanks again Simon.
Do learnig to & from others....
Bins Davis
|
|
|
|
|
Guys, this is very annoying. I'm almost at completion of this project and i'm still stuck. I declare a form object and add it to the MDI form,
ChildForm childFormObj = new ChildForm();<br />
childFormObj.MdiParent = this;<br />
childFormObj.Show() ;
Then i maximise it, childFormObj.WindowState = WindowState.Maximised;
Even in the child form its window state is already maximised. but it just won't comply.
What do i do, Please
He who goes for revenge must first dig two graves.
|
|
|
|
|
This works for me - note the changes on the last line!
ChildForm childFormObj = new ChildForm();
childFormObj.MdiParent = this;
childFormObj.Show();
childFormObj.WindowState = FormWindowState.Maximized;
Dave
|
|
|
|
|
I draw some edges on my control which relate to nodes. When i remove a node, i call RemoveEdge(List<edgeobj> edgeList) and pass it node.EdgeList which is a list of edges which belong to that node.
public void RemoveEdge(List<edgeobj> edgeList)
{
for (int i = 0; i < edgeList.Count; i++)
{
Trace.WriteLine("i == " + i);
RemoveEdge(edgeList[i]);
}
}</edgeobj>
public void RemoveEdge(EdgeObj edge)
{
Trace.WriteLine("edge == " + edge.Label.Text);
if (!_edgeItems.Contains(edge))
{
Trace.WriteLine("not in list");
return;
}
_edgeItems.Remove(edge);
edge.ParentNode.RemoveEdge(edge);
edge.ChildNode.RemoveEdge(edge);
edge.Dispose();
edge = null;
}
The problem is 'i' never gets past 1, so i am left with edges that dont connect to nodes being drawn. Can anyone see whats going wrong?
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Have you tried working backwards? When removing items your list gets adjusted as the items are removed.
for (int i = edgeList.Count; i > 0; i--)
{ Trace.WriteLine("i == " + i);
RemoveEdge(edgeList[i]);
}
Hope this helps
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Ashfield,
That gave me an out of range exception, so i did the below and it works fine now.
for (int i = edgeList.Count - 1; i > -1; i--)
{}
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Ah well, the old memory isn't what it used to be. Pleased it helped though.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Looks like you've got some recursion problems to me.
you're calling RemoveEdge on the parent node, which will recur, as you are passing the same edge into the method.
I suspect you're either getting a null object or a stack overflow exception, which is then causing it to break out of the for loop.
Hit Debug->Exceptions and tick the "Common language runtime exceptions" box to make the debugger break when an exception occurs.
(If you don't understand the exception, post it here with the stack trace and message)
Simon
|
|
|
|
|
parentNode.RemoveEdge calls its own method, not the one i have posted.
Regards,
Gareth.
(FKA gareth111)
|
|
|
|