|
Hi All
I am planning to write a monitor for my server which has seperate TCP/IP connections to and from external servers. I am frequently receiving and sending messages to them. I am using sockets for connections but I would also like to monitor the status of each TCP/IP connection (both incoming and outgoing), whether the connection is still there or not. Because in some cases these external servers goes down or due to network problem they loose connection without informing my server.
According to my understanding and knowledge, sockets can create a connection but you can only know about status of the connection (whether it is success or exception), when you send some data on it. This idea works when I will be using the connections for non stop communication but my concern is about the time when we do not have much messages comming and we are not sure when will the next message come. one idea was, I periodically send test messages to outgoing connections to external servers but then how these external systems know that it is just a test message (as there is no protocol between us like this). And also what happen to the incomming connections. Because I cannot just start sending messages on these connections as there could be some message comming to my server.
Let me know with your suggestions and questions.
Thanks
Adeel Aslam
|
|
|
|
|
This is useless because the monitor can't do anything. Your monitor won't know there is a problem until it's too late. Your application will also have to interact with this monitor so it knows what it's looking for, no what it's no longer supposed to be looking for. If the server cuts out, your app, nor your monitor will never know about untilo your app tries to send. The only thing will happen is that your app and the monitor will just be waiting for a response that won't come.
The best way to handle this is better exception handling and recovery on your side. Even with the monitor, it's what you're going to be forced to do anyway.
|
|
|
|
|
Hello All!!!
I have JUST (like 2 days ago) started learning Visual C# 2005 and because of my history with C++, I am picking it up like ET on Smarties. I was messing around one day with Form.Opacity and thought, hmmm... wouldn't it be cool if you could not only fade a window in when the program loaded but fade it out as well when it quit!?! Well...I have tried the following:
Attempt 1:
Created two timers, one for fading the window in and another to fade it out. The <timer>.Interval for both was 1ms. This worked beautifully for the window fading in when the program started because you would still be able to use any controls on the form while it was fading it in. Fading out posed a problem. I did some snooping and wrote an override for OnClosing using the event properties of the form from [Design]. I then ran into a problem. I cannot delay the close event while the window fades out.
Attempt 2:
Created infinite for loops to be executed during the Constructor and OnClosing functions of the form. Came into another problem...on construction of the form you would be greeted with an hourglass icon while the form faded in. OnClosing resulted in the form being repainted as if it were not responding if you changed focus to another window...I chalk this up to Windows XP actually.
Questions:
Is there a way to intercept or redirect the Event created by that wonderfully close button in the top right corner of the window so that I may fade the window AND THEN process the close event? Would there be a way to implement this into a class library? and last but not least...I'm reading Beginning Visual C# 2005 by Wiley/Wrox (at the time I was writing this I was at chapter 10), can anyone offer any other titles that I can look into that will further my knowledge of this quite interesting language and all the .NET has to offer through it?
I thank you all for your time.
-=Wraith-Lunati=-
|
|
|
|
|
The EventArgs that is passed into the closing event has a flag you can set to reject the closing event, so your form won't close. You can do this, then set the timer to fade out, and have the timer when it ends, close the form. You'd need a flag you set so that the closing event doesn't get killed again the second time.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I like this idea...
Let me get this right though:
DummyClose function attached to FormClosing to be created.
DummyClose will cancel the OnClosing if window opaque and make it fade first.
FadeOut timer needs to call this.Close() which will check opaque and actually close.
BTW thank you for such a quick reply!!!
|
|
|
|
|
Well, it's not a dummy close, it's an event handler which cancels the close if the form is opaque and starts a timer which fades the form and then closes it again.
Welcome
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
How bout TrojanClose? lol.
|
|
|
|
|
OMG That is sooo cool!!! Now I will attempt to make this into an abstract class library I can use as a base for forms.
This is made from a Windows Application template...try it out!!!
If you copy and paste it won't work I hope most of you know that :P
WARNING: This code is just an example. I assume most of you know what to do or you wouldn't even try.
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
<br />
namespace WindowsApplication1<br />
{<br />
public partial class Form1 : Form<br />
{<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
FadeIn.Enabled = true;
}<br />
<br />
private void FadeIn_Tick(object sender, EventArgs e)<br />
{<br />
Opacity += 0.005;<br />
if (Opacity > 0.995)<br />
FadeIn.Enabled = false;<br />
}<br />
<br />
private void FadeOut_Tick(object sender, EventArgs e)<br />
{<br />
Opacity -= 0.0025;<br />
if (Opacity < 0.0025)<br />
{<br />
FadeOut.Enabled = false;<br />
this.Close();<br />
}<br />
}<br />
<br />
private void DummyClose(object sender, FormClosingEventArgs e)<br />
{<br />
if (Opacity > 0)<br />
{<br />
FadeIn.Enabled = false;
FadeOut.Enabled = true;
e.Cancel = true;<br />
}<br />
}<br />
}<br />
}<br />
|
|
|
|
|
It sounds pretty cool, I reckon if you wrote up an article about a new base Form class which offered this, a lot of people would use it.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I'm still pretty new to this site and I have never written an article before. Though I have read a few of them from here before and...well...some of them make me cringe sometimes the way they are laid out. Would you be willing to offer some of your obvious wisdom into helping me complete this task via e-mail? if so reply via said medium and we'll soon talk.
Thank you...
|
|
|
|
|
You need to confirm your email address before I can send you an email. I'd give you my email address publically, but who knows what email I'd get if I did that ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
hi all
I wanted a way to kill a spesific proccess for example winword.exe for a spesific user ( the user that runs the program)
there is more than one user logged on to the server so i cant have it kill all winword.exe's
any idea on how to do this?
|
|
|
|
|
You may have to P/Invoke OpenProcessToken (advapi32)[^]. Get the token information and check if the username and the process name are the one you want to kill. Get the handle and using a win32 method kill the application.
|
|
|
|
|
I was thinking more something like
For Each proc As Process In Process.GetProcessesByName("process name here") proc.CloseMainWindow() 'ask the process to exit.
proc.WaitForExit(10000) 'wait up to 10 seconds.
If Not proc.HasExited Then
proc.Kill() 'force the process to exit.
End If
Next proc
But this is in VB
|
|
|
|
|
Well, that's trivial to convert to C#.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
I don't think you can get the user running the process by using the System.Diagnostics.Process class. You will have to either use P/Invoke as I suggested before or you could use WMI to get the user name of the process.
System.Management.ManagementObjectSearcher moSearch;
string sQuery = "";
System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("winword");
foreach (System.Diagnostics.Process p in processes)
{
sQuery = "Select * From Win32_Process Where ProcessID = " + p.Id;
moSearch = new System.Management.ManagementObjectSearcher(sQuery);
string[] args = new string[5];
foreach (System.Management.ManagementObject mo in moSearch.Get())
{
mo.InvokeMethod("GetOwner", args);
if (args[0] == strNameToSearch)
System.Diagnostics.Process.GetProcessById(p.Id).Kill();
}
}
|
|
|
|
|
I have a small problem with System.Management
do I need to import something to make this work?
|
|
|
|
|
i found this
foreach (System.Diagnostics.Process proc in System.Diagnostics.Process.GetProcessesByName(textBox1.Text))
{
proc.CloseMainWindow();
proc.WaitForExit(10000);
if (!proc.HasExited)
{
proc.Kill();
}
}
but im having trouble inputing the proccess i want to kill
it seems like no mater what i enter it allways returns a null value to proc
|
|
|
|
|
Hello,
Have you checked the name of the process in the taskmanager?
Have you debugged the foreach, are you entering it?
You should also dispose your process instances, even if you don't kill the instance.
proc.Dispose();
Hope it helps!
All the best,
Martin
|
|
|
|
|
yes its "WINWORD.EXE"
yes i am entering it only once
im not sure what you mean by dispose():
where would i put that and why. im not trying to dispose a proccess that has been created by me
|
|
|
|
|
Hello,
OK, So you are entering the loop, that means he found an instance.
So whats the problem now?
crash893 wrote: im not sure what you mean by dispose():
where would i put that and why. im not trying to dispose a proccess that has been created by me
Disposing frees the memory from any connections, so that the GarbadgeCollector (GC) can free the memory.
With the GetProcessesByName method you created an instance (or more) of the process class (Has nothing to to with creating an new winword instance).
You would also have to (or should) dispose the instances if you don't kill the process.
In your code this would mean:
foreach (System.Diagnostics.Process proc in System.Diagnostics.Process.GetProcessesByName(textBox1.Text))
{
proc.CloseMainWindow();
proc.WaitForExit(10000);
if (!proc.HasExited)
{
proc.Kill();
}
proc.Dispose();
}
All the best,
Martin
|
|
|
|
|
everything looked like its working right but i ran into a small snag
I ran it on a terminal server ( where many people log on to run apps) and the proccess killed EVERY proccess with the name i wanted (not good)
Here is an example of what i see in taskman
Red is the scope of what it killed I am hopeing to narrow it down to who ever runs it ( in this case me rbarbrow) in BLUE
[IMG]http://i13.tinypic.com/6bcvou9.png[/IMG]
|
|
|
|
|
Hello,
Sorry for the late response!
Maybe the process member "MachineName" helps you to find the wright process.
All the best,
Martin
|
|
|
|
|
1.
int ThisSession = System.Diagnostics.Process.GetCurrentProcess().SessionId;
2.
int thisPID = System.Diagnostics.Process.GetCurrentProcess().Id;
3.
foreach (System.Diagnostics.Process proc in System.Diagnostics.Process.GetProcessesByName(application))
4.
{
5.
if (proc.SessionId == ThisSession)
6.
{
7.
proc.CloseMainWindow();
8.
proc.WaitForExit(Wait);
9.
if (!proc.HasExited)
10.
{
11.
proc.Kill();
12.
}
13.
proc.Dispose();
14.
}
|
|
|
|