• 0

[.NET][.C#] What Event Fires When Data Is Sent Via Pipe?


Question

I have an object and I want it to be self-aware of when it is changing AppDomains or other similar significant boundaries. For instance, traveling across a network (either on the same computer or to another computer), being passed to another application on the same or another computer, and so on...

Can someone compile a list or at least start a list of .NET / C# events I should listen to?

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

From app to app you're dealing with window messages. Use the following function to receive/interpret window messages:

  protected override void WndProc(ref Message m)
		{
  switch (m.Msg)
			{ 
				case number:
						// if this msg is sent, do this.
						break;
			}
			base.WndProc(ref m);
		}

Sending a message is as simple as using the Message.Create() command in C# or the SendMessage WinAPI. This is great for cross-communication between apps. As for communication across networks or PC to PC you'll probably be dealing with sockets. Sockets have their own receive data method which you'll want to create in a separate thread (if you want to listen for a response for any given length of time):

						while (true)

						{
							rc = clientSocket.Receive(receiveBuffer);

							Console.WriteLine("Server: Read {0} bytes", rc);

							if (rc == 0)

								break;

						}

Socket tutorial: http://www.winsocketdotnetworkprogramming....nication8b.html

I'm not sure if this is what you're looking for though. Your description was a little hard for me to understand (not sure what you're trying to accomplish).

Link to comment
Share on other sites

  • 0

Thanks Se7enVII. The WndProc may be very useful.

I'll try to better explain my scenario. I'm trying to create an object that holds a string and (obviously) can get passed around to other applications and/or systems. I want to be able to know when the object is passed around to do some error checking, etc.... I guess the information missing is that I'm not the one who will be doing the coding to actually pass the object around, so I need to detect when my object is sent/passed somewhere significant (to another application, across a network, etc....) rather than relying on the other coder to tell my object when it is passed somewhere significant.

Link to comment
Share on other sites

  • 0
Thanks Se7enVII. The WndProc may be very useful.

I'll try to better explain my scenario. I'm trying to create an object that holds a string and (obviously) can get passed around to other applications and/or systems. I want to be able to know when the object is passed around to do some error checking, etc.... I guess the information missing is that I'm not the one who will be doing the coding to actually pass the object around, so I need to detect when my object is sent/passed somewhere significant (to another application, across a network, etc....) rather than relying on the other coder to tell my object when it is passed somewhere significant.

I'm not sure if this is possible (if I understand correctly). Without having code in each app the object is passed to or an app on each PC to interpret what the object is/does then it is impossible (AFAIK) to have the object do anything.

If you aren't controlling the object that is being passed then it's going to be extremely difficult (the object can't do anything on its own). The only possible way I could see this working is if you were to inject code (dll injection) from one process to another that can handle the object that is being passed to them (you'd have to know how/what methods the object is being passed) and have the code send messages back to your main app relating to the object. This obviously wouldn't work cross PC/network and would require you to have separate executables -- "listeners" you might say, on each of those PCs to send the data back to your original app via sockets.

Again if I understood it correctly, this doesn't really seem feasible.

Link to comment
Share on other sites

  • 0

Okay, is this at least partially solvable for certain transport types? For instance, all .NET remoting calls or all Web Service calls?

I'm a little surprised there isn't an AppDomain.Changing event. One thought I'm having is to save some application/machine information when the object is created and check that information against the same references whenever the object's string data is accessed. It's a bit more expensive, but I think it will make up for the lack of system events I'm looking for.

Link to comment
Share on other sites

  • 0

in case anyone was wondering, I just used these two pieces of information to try and tell if the object had moved significantly:

AppDomain.CurrentDomain.FriendlyName

Environment.MachineName

anyone else have any other suggestions?

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.