C# Wait?

Home Forums Discussions Support C# Wait?

Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #9587
    ZiJer
    Participant

      How to intercept outgoing packet and wait until the Console.ReadKey() be proceeded?
      So packet will not be sent until the user type anything.

      Как перехватить исходящий пакет и подождать, пока Console.ReadKey() не будет продолжено?
      Т.е. пакет не будет отправлен, пока пользователь не нажмет что нибудь.

      #9588
      Vadim Smirnov
      Keymaster

        Just add Console.ReadKey() before forwarding packet to the network interface. Below is a part of PassThru C# sample with Console.ReadKey() added.

        Please note, that all the networking for the selected network interface will be frozen while console waits for the input…

        while (packetsCount > 0)
        {
        	manualResetEvent.WaitOne();
        
        	while (Ndisapi.ReadPacket(driverPtr, ref request))
                {
                	--packetsCount;
        
                        buffer = (INTERMEDIATE_BUFFER)Marshal.PtrToStructure(bufferPtr, typeof(INTERMEDIATE_BUFFER));
        
                        WriteToConsole(buffer, bufferPtr);
        
                        if (buffer.m_dwDeviceFlags == Ndisapi.PACKET_FLAG_ON_SEND)
        		{
        			Console.ReadKey();
        	                Ndisapi.SendPacketToAdapter(driverPtr, ref request);
        		}
                        else
                                Ndisapi.SendPacketToMstcp(driverPtr, ref request);
                }
        
                manualResetEvent.Reset();
        }
      Viewing 2 posts - 1 through 2 (of 2 total)
      • You must be logged in to reply to this topic.