Click here to Skip to main content
15,064,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm working on developing Chrome Extension for several weeks. I have almost completed a demo version of chrome extension now. but I have one problem I don't know so that I wanna get some help from you guys.I've written the host in c# lang My host program is running even though the chrome browser was closed. and then my host program is launching again when chrome browser was re-open. which means my host programs are stacking whenever chrome browser was all closing then re-opening. how can I solve this problem? Plz, help me and advice me.

Thanks in advance :D


What I have tried:

I tried to control the host app using this code


[DllImport("Kernel32")]
private static extern bool SetConsoleCtrlHandler(EventHandler handler, bool add);

private delegate bool EventHandler(CtrlType sig);
static EventHandler _handler;

enum CtrlType
{
  CTRL_C_EVENT = 0,
  CTRL_BREAK_EVENT = 1,
  CTRL_CLOSE_EVENT = 2,
  CTRL_LOGOFF_EVENT = 5,
  CTRL_SHUTDOWN_EVENT = 6
}

private static bool Handler(CtrlType sig)
{
  switch (sig)
  {
      case CtrlType.CTRL_C_EVENT:
      case CtrlType.CTRL_LOGOFF_EVENT:
      case CtrlType.CTRL_SHUTDOWN_EVENT:
      case CtrlType.CTRL_CLOSE_EVENT:
      default:
          return false;
  }
}


static void Main(string[] args)
{
  // Some biolerplate to react to close window event
  _handler += new EventHandler(Handler);
  SetConsoleCtrlHandler(_handler, true);
  ...
}


but this code is not working and not exiting the host app
Posted
Comments
Richard MacCutchan 30-Jun-20 5:12am
   
I cannot see any connection between the above code and a Chrome extension. Also, your application appears to set a console handler and then terminate. I suspect that is not what you want it to do.
member5320 2-Jul-20 1:10am
   
I just want to know when is the browser is closing and when on browser closing event the host application must also be killed.
Richard MacCutchan 2-Jul-20 4:39am
   
Sorry, I still do not see what that has to do with the above code.
member5320 3-Jul-20 0:53am
   
I've found some code in c to close the native app like this


std::string req;
while(!(req=read_request()).empty())
{
//process request and send response
}




and this is my c# code to get the data from the browser


private static string OpenStandardStreamIn()
{
using var stdin = Console.OpenStandardInput();
string input = "";
int length = 0;
byte[] bytes = new byte[4];
stdin.Read(bytes, 0, 4);
length = BitConverter.ToInt32(bytes, 0);
byte[] buff = new byte[length];
stdin.Read(buff, 0, buff.Length);
input += Encoding.UTF8.GetString(buff);
return input;
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900